Example #1
0
 /// <summary>
 /// 取消下载任务
 /// </summary>
 public void Cancel()
 {
     lock (_external_lock)
     {
         lock (_thread_flag_lock)
         {
             //Tracer.GlobalTracer.TraceInfo("---CANCELLED---");
             if (((_download_thread_flag & 0xffffff) & (_DOWNLOAD_THREAD_FLAG_STOPPED | _DOWNLOAD_THREAD_FLAG_FINISHED)) != 0)
             {
                 return;
             }
             if ((_download_thread_flag & 0xffffff) == _DOWNLOAD_THREAD_FLAG_READY)
             {
                 _download_thread_flag = (_download_thread_flag | _DOWNLOAD_THREAD_FLAG_STOPPED) & ~_DOWNLOAD_THREAD_FLAG_READY;
                 return;
             }
             else if ((_download_thread_flag & 0xffffff) == _DOWNLOAD_THREAD_FLAG_PAUSED)
             {
                 _download_thread_flag = (_download_thread_flag | _DOWNLOAD_THREAD_FLAG_STOPPED) & ~_DOWNLOAD_THREAD_FLAG_PAUSED;
                 return;
             }
             else if (((_download_thread_flag & 0xffffff) & (_DOWNLOAD_THREAD_FLAG_STARTED | _DOWNLOAD_THREAD_FLAG_START_REQUESTED)) != 0)
             {
                 _download_thread_flag |= _DOWNLOAD_THREAD_FLAG_STOP_REQUESTED;
             }
         }
         _monitor_thread_created.Wait();
         _monitor_thread.Join();
         _monitor_thread_created.Reset();
         Dispose();
     }
     try { TaskCancelled?.Invoke(this, new EventArgs()); }
     catch { }
 }
Example #2
0
        public void CancelTask()
        {
            try {
                if (repo.Active)
                {
                    repo.CancelDownloads();
                    Active = false;
                    Status = "Task cancelled";
                    ComicConvert.ImgsToCbz(repo.Location, OutputFileName);
                    if (TaskCancelled != null)
                    {
                        TaskCancelled.Invoke(this, new EventArgs());
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            Active = false;
            Status = "Task cancelled";
            if (TaskCancelled != null)
            {
                TaskCancelled.Invoke(this, new EventArgs());
            }
        }
Example #3
0
        public void Cancel()
        {
            lock (_external_lock)
            {
                lock (_thread_flag_lock)
                {
                    //cancelled state
                    if ((_upload_thread_flag & (_UPLOAD_THREAD_FLAG_CANCELLED | _UPLOAD_THREAD_FLAG_FINISHED)) != 0)
                    {
                        return;
                    }
                    //ready state
                    if ((_upload_thread_flag & _UPLOAD_THREAD_FLAG_READY) != 0)
                    {
                        _upload_thread_flag = (_upload_thread_flag | _UPLOAD_THREAD_FLAG_CANCELLED) & ~_UPLOAD_THREAD_FLAG_READY;
                        return;
                    }
                    //paused state
                    if ((_upload_thread_flag & _UPLOAD_THREAD_FLAG_PAUSED) != 0)
                    {
                        _upload_thread_flag = (_upload_thread_flag | _UPLOAD_THREAD_FLAG_CANCELLED) & ~_UPLOAD_THREAD_FLAG_PAUSED;
                        return;
                    }
                    if ((_upload_thread_flag & (_UPLOAD_THREAD_FLAG_STARTED | _UPLOAD_THREAD_FLAG_START_REQUESTED)) != 0)
                    {
                        Tracer.GlobalTracer.TraceInfo("---CANCELLED---");
                        _upload_thread_flag |= _UPLOAD_THREAD_FLAG_CANCEL_REQUESTED;
                    }

                    _monitor_thread_created.Wait();
                    _monitor_thread_exited.Wait();
                    _monitor_thread_exited.Reset();
                    _monitor_thread_created.Reset();
                    Dispose();
                }
            }
            try { TaskCancelled?.Invoke(this, new EventArgs()); } catch { }
        }
        public void RaiseTaskCancelled(Task task, [CallerMemberName] string taskName = default)
        {
            var status = $"[Cancelled] Task: {taskName}. status: {task.Status}".AppendMainThreadAlert();

            TaskCancelled?.Invoke(this, new TaskStatusChangedEventArgs(task, status));
        }
Example #5
0
 private void _on_task_cancelled(object sender, EventArgs e)
 {
     try { TaskCancelled?.Invoke(sender, e); }
     catch { }
 }
 private void OnTaskCancelled()
 {
     TaskCancelled?.Invoke(this, EventArgs.Empty);
 }