Beispiel #1
0
 public void JobError(BITS.IBackgroundCopyJob pJob, BITS.IBackgroundCopyError pError)
 {
     pJob.Cancel();
     aTimer.Stop();
     pError.GetErrorDescription((uint)CultureInfo.GetCultureInfo("en-US").LCID, out string errdesc);
     if (errdesc != null)
     {
         installationPackage.HandleDownloadError(errdesc);
     }
     installationPackage.HandleProgress(installationPackage);
 }
        public void JobError(BITS.IBackgroundCopyJob pJob, BITS.IBackgroundCopyError pError)
        {
#if DEBUG
            Logger.GetLogger().Info($"JobError event on download file: {_downloadFileName}");
#endif
            pJob.Cancel();
            _aTimer.Stop();
            pError.GetErrorDescription((uint)CultureInfo.GetCultureInfo("en-US").LCID, out string errdesc);
            if (!string.IsNullOrWhiteSpace(errdesc))
            {
                installationPackage.HandleDownloadError(errdesc);
            }
            installationPackage.HandleProgress(installationPackage);
        }
        private void CancelJob()
        {
            try
            {
                _job?.Cancel();
            }
#if DEBUG
            catch (Exception e)
#else
            catch (Exception)
#endif
            {
#if DEBUG
                Logger.GetLogger().Error($"error while trying to cancel BITS job: {e.Message}");
#endif
            }
        }
Beispiel #4
0
        /// <summary>
        /// Demonstrate how to poll for a job to be finished. A job has to be in a
        /// final state to be finished.
        /// </summary>
        /// <param name="job">Input job to wait for completion on.</param>
        private void Poll(BITS.IBackgroundCopyJob job)
        {
            // Poll for the job to be complete in a separate thread.
            new System.Threading.Thread(() => {
                try
                {
                    bool jobIsFinal = false;
                    while (!jobIsFinal)
                    {
                        BITS.BG_JOB_STATE state;
                        job.GetState(out state);
                        switch (state)
                        {
                        case BITS.BG_JOB_STATE.BG_JOB_STATE_ERROR:
                            job.Cancel();
                            break;

                        case BITS.BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED:
                            job.Complete();
                            break;

                        case BITS.BG_JOB_STATE.BG_JOB_STATE_CANCELLED:
                        case BITS.BG_JOB_STATE.BG_JOB_STATE_ACKNOWLEDGED:
                            jobIsFinal = true;
                            break;

                        default:
                            Task.Delay(500); // delay a little bit
                            break;
                        }
                    }
                    // Job is in a final state (cancelled or acknowledged)
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    MessageBox.Show(
                        String.Format(Properties.Resources.ErrorBitsException, ex.HResult, ex.Message),
                        Properties.Resources.ErrorTitle
                        );
                }
            }
                                        ).Start();
        }
Beispiel #5
0
 public void JobError(BITS.IBackgroundCopyJob pJob, BITS.IBackgroundCopyError pError)
 {
     pJob.Cancel();
 }