protected virtual void OnEnding() { ScheduleState = DownloaderScheduleState.Ended; if (Ending != null) { Ending(this, EventArgs.Empty); } }
private void SetState(DownloaderState value) { state = value; if (state == DownloaderState.EndedWithError) { ScheduleState = DownloaderScheduleState.Error; } OnStateChanged(); }
public void Start() { ScheduleState = DownloaderScheduleState.Working; if (state == DownloaderState.NeedToPrepare) { SetState(DownloaderState.Preparing); StartToPrepare(); } else if ( state != DownloaderState.Preparing && state != DownloaderState.Pausing && state != DownloaderState.Working && state != DownloaderState.WaitingForReconnect) { SetState(DownloaderState.Preparing); StartPrepared(); } }
public void Pause() { ScheduleState = DownloaderScheduleState.Paused; if (state == DownloaderState.Preparing || state == DownloaderState.WaitingForReconnect) { Segments.Clear(); mainThread.Abort(); mainThread = null; SetState(DownloaderState.NeedToPrepare); return; } if (state == DownloaderState.Working) { SetState(DownloaderState.Pausing); while (!AllWorkersStopped(5)) { ; } lock (threads) { threads.Clear(); } mainThread.Abort(); mainThread = null; if (RemoteFileInfo != null && !RemoteFileInfo.AcceptRanges) { // reset the segment Segments[0].StartPosition = 0; } SetState(DownloaderState.Paused); } }