示例#1
0
        private void Thread_Failed(object sender, ThreadExitedArgs e)
        {
            bool isRaiseFailed = false;

            lock (this._syncRoot)
            {
                if (e.WorkID != this._workID)
                {
                    return;                          // 这次操作已经过期
                }
                if (this._status != DownloaderStatuses.Downloading)
                {
                    return;                                                // 只有Downloading状态才可能变为Failed状态
                }
                this.RefreshWorkID();
                this._status = DownloaderStatuses.Failed;
                this._progressTimer.Dispose();
                this._progressTimer = null;
                this.ClearThread();
                this.CacheConfig();// 保存文件配置以便以后继续下载
                this._sourceProvider = null;
                this._writer.Dispose();
                this._writer = null;

                isRaiseFailed = true;
            }// lock

            if (isRaiseFailed)
            {
                this.OnFailed();
            }
        }
示例#2
0
        private void OnCompleted(ThreadExitedArgs e)
        {
            EventHandler <ThreadExitedArgs> handler = this.Completed;

            if (handler != null)
            {
                handler(this, e);
            }
        }
示例#3
0
        private void Thread_Completed(object sender, ThreadExitedArgs e)
        {
            bool isRaiseCompleted = false;

            lock (this._syncRoot)
            {
                if (e.WorkID != this._workID)
                {
                    return;                          // 这次操作已经过期
                }
                if (this._status != DownloaderStatuses.Downloading)
                {
                    return;                                                // 只有Downloading状态才可能变为Failed状态
                }
                if (!this._writer.IsCompleted())
                {
                    return;                             // 文件下载还没有完成
                }
                this.RefreshWorkID();
                this._status = DownloaderStatuses.Completed;
                this._progressTimer.Dispose();
                this._progressTimer = null;
                this.ClearThread();
                this._sourceProvider = null;
                this._writer.Dispose();
                this._writer = null;

                if (File.Exists(this._savePath))
                {
                    File.Delete(this._savePath);
                }
                File.Move(this._tmpPath, this._savePath);
                if (File.Exists(this._configPath))
                {
                    File.Delete(this._configPath);
                }

                isRaiseCompleted = true;
            }// lock

            if (isRaiseCompleted)
            {
                this.OnCompleted();
            }
        }