SharpBits.Base.BitsManager.CreateJob C# (CSharp) Method

CreateJob() public method

Creates a new transfer job.
public CreateJob ( string displayName, JobType jobType ) : BitsJob
displayName string Null-terminated string that contains a display name for the job. Typically, the display name is used to identify the job in a user interface. Note that more than one job may have the same display name. Must not be null.The name is limited to 256 characters, not including the null terminator.
jobType JobType Type of transfer job, such as JobType.Download. For a list of transfer types, /// see the enumeration.
return BitsJob
        public BitsJob CreateJob(string displayName, JobType jobType)
        {
            Guid guid;
            IBackgroundCopyJob copyJob;
            this.BackgroundCopyManager.CreateJob(displayName, (BGJobType)jobType, out guid, out copyJob);
            BitsJob job;
            lock (this.Jobs)
            {
                job = new BitsJob(this, copyJob);
                this.Jobs.Add(guid, job);
            }

            if (null != this.jobAdded)
            {
                this.jobAdded(this, new NotificationEventArgs(job));
            }

            return job;
        }

Usage Example

        private bool DownloadMovies() {
            using (var bitsManager = new BitsManager()) {
                bitsManager.OnInterfaceError += (sender, args) => _logger.Error("BITS error: {0}\n{1}", args.Message, args.Description);

                if (CheckRunningJob(bitsManager)) {
                    return false;
                }

                var moviesToDownload = _movies
                    .Where(m => string.IsNullOrEmpty(m.LocalPath) || !File.Exists(m.LocalPath))
                    .Take(200)
                    .ToList();

                if (moviesToDownload.Any()) {
                    var job = bitsManager.CreateJob("AerialForWindows", JobType.Download);
                    job.Priority = JobPriority.Low;
                    job.MinimumRetryDelay = 5 * 60; // 5 minutes
                    job.NoProgressTimeout = 30 * 60; // 30 minutes

                    foreach (var movie in moviesToDownload) {
                        var localPath = GetLocalPathForMovie(movie);
                        movie.LocalPath = localPath;
                        job.AddFile(movie.DownloadUrl, localPath);
                    }

                    job.Resume();
                    Settings.Instance.BitsJobId = job.JobId;
                    Settings.Instance.Save();

                    _logger.Debug($"Startet download of {moviesToDownload.Count} files");

                    return true;
                }
                return false;
            }
        }