示例#1
0
 protected virtual void OnEnding()
 {
     ScheduleState = DownloaderScheduleState.Ended;
     if (Ending != null)
     {
         Ending(this, EventArgs.Empty);
     }
 }
示例#2
0
 private void SetState(DownloaderState value)
 {
     state = value;
     if (state == DownloaderState.EndedWithError)
     {
         ScheduleState = DownloaderScheduleState.Error;
     }
     OnStateChanged();
 }
示例#3
0
        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();
            }
        }
示例#4
0
        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);
            }
        }