private static bool ExecuteJob(BITS.IBackgroundCopyJob job) { var jobIsFinal = false; var jobCompleted = false; while (!jobIsFinal) { job.GetState(out var 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(); jobCompleted = true; break; case BITS.BG_JOB_STATE.BG_JOB_STATE_CANCELLED: jobIsFinal = true; break; case BITS.BG_JOB_STATE.BG_JOB_STATE_ACKNOWLEDGED: jobIsFinal = true; break; default: break; } } return(jobCompleted ? true : false); }
private bool CreateJob(int type, out BITS.GUID jobGuid, out BITS.IBackgroundCopyJob job) { var mgr = new BITS.BackgroundCopyManager2_5(); var randJobName = RandomString(15); switch (type) { case 0: mgr.CreateJob(randJobName, BITS.BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out jobGuid, out job); break; case 1: mgr.CreateJob(randJobName, BITS.BG_JOB_TYPE.BG_JOB_TYPE_UPLOAD, out jobGuid, out job); break; case 2: mgr.CreateJob(randJobName, BITS.BG_JOB_TYPE.BG_JOB_TYPE_UPLOAD_REPLY, out jobGuid, out job); break; default: jobGuid = new BITS.GUID(); job = null; break; } return(job != null); }