Пример #1
0
        /// <summary>
        /// 任务暂停
        /// </summary>
        public void Pause()
        {
            try
            {
                Task.Factory.StartNew(() =>
                {
                    //此功能仅对上传下载有效
                    if (_Info.Method != Method.Upload && _Info.Method != Method.Download)
                    {
                        return;
                    }

                    _Info.ResultCode = ResultCode.Paused;

                    if (TaskThread != null)
                    {
                        TaskThread.Abort();
                        TaskThread = null;
                    }
                    else
                    {
                        if (Paused != null)
                        {
                            Paused(this, new FileEventArgs(_Info, null));
                        }
                    }
                });
            }
            catch { };
        }
Пример #2
0
 public void CloseThread()
 {
     if (TaskThread.ThreadState != ThreadState.Aborted)
     {
         TaskThread.Abort();
     }
 }
Пример #3
0
 public void Stop()
 {
     if (_running)
     {
         _running = false;
         TaskThread.Abort();//之前先释放MessageService的话,进程里仍在使用MessageService会报错,现在改为先释放Thread试试
     }
 }
Пример #4
0
 public void RemoveTask()
 {
     Active = false;
     if (GetRunningStage() != TaskRunStage.Running)
     {
         TaskThread.Abort();
         EventAfterRun();
     }
 }
Пример #5
0
 public void Stop()
 {
     if (_running)
     {
         _running = false;
         TaskThread.Abort();//之前先释放MessageService的话,进程里仍在使用MessageService会报错,现在改为先释放Thread试试
         //SaveThread.Abort();
         //MessageService.Dispose();
         //MessageService = null;
     }
 }
Пример #6
0
 public void Dispose()
 {
     if (_running)
     {
         try
         {
             _running = false;
             TaskThread.Abort();
         }
         catch (Exception) { }
     }
 }
Пример #7
0
        /// <summary>
        /// 任务取消
        /// </summary>
        public void Cancel()
        {
            try
            {
                Task.Factory.StartNew(() =>
                {
                    //此功能仅对上传下载有效
                    if (_Info.Method != Method.Upload && _Info.Method != Method.Download)
                    {
                        return;
                    }

                    _Info.ResultCode = ResultCode.Cancelled;
                    if (TaskThread != null)
                    {
                        TaskThread.Abort();
                        TaskThread = null;
                    }
                    else
                    {
                        if (_Info.Method == Method.Upload)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FtpHelper.DeleteRemoteFile(_Url + (_Info.NewFilePath == "" ? "" : _Info.NewFilePath + "/") + _Info.NewFileName + ".tmp");
                            });
                            FtpHelper.FtpUploadFileInfoList.Remove(_Info);
                        }
                        else
                        {
                            FileHelper.DeleteFile((_Info.NewFilePath == "" ? "" : _Info.NewFilePath + "/") + _Info.NewFileName + ".tmp");
                            FtpHelper.FtpDownloadFileInfoList.Remove(_Info);
                        }
                        FileHelper.DeleteFile("./Tasks/" + _Info.Method.ToString() + "File/" + _Info.FileNo + ".dat");
                        if (Cancelled != null)
                        {
                            Cancelled(this, new FileEventArgs(_Info, null));
                        }
                    }
                });
            }
            catch { };
        }