public void Initialize() { BitsManager bitsManager = new BitsManager(); bitsManager.OnInterfaceError += new EventHandler <BitsInterfaceNotificationEventArgs>(bitsManager_OnInterfaceError); BitsJobs jobs = bitsManager.EnumJobs(Owner); bool foundJob = false; foreach (BitsJob job in jobs.Values) { if (job.DisplayName == Name) { // if not transferring, then it is dangling so remove it #warning Fix behaviour here if (true) //job.State != JobState.Transferring) { { job.Cancel(); } else { UnderlyingJob = job; foundJob = true; } } } if (!foundJob) { UnderlyingJob = bitsManager.CreateJob(Name, JobType); OnCreate(UnderlyingJob); } UnderlyingJob.OnJobErrorEvent += new EventHandler <JobErrorNotificationEventArgs>(UnderlyingJob_OnJobErrorEvent); UnderlyingJob.OnJobTransferredEvent += new EventHandler <JobNotificationEventArgs>(UnderlyingJob_OnJobTransferredEvent); }
public BitsJobs EnumJobs(JobOwner jobType) { IEnumBackgroundCopyJobs jobList = null; this.manager.EnumJobs(Convert.ToUInt32(jobType), out jobList); if (this.jobs == null) { this.jobs = new BitsJobs(this, jobList); } else { this.jobs.Update(jobList); } return(this.jobs); }