/// <summary> /// 暂停下载任务 /// </summary> public void Pause() { lock (_external_lock) { lock (_thread_flag_lock) { if ((_download_thread_flag & 0xffffff) == _DOWNLOAD_THREAD_FLAG_READY) { _download_thread_flag = (_download_thread_flag | _DOWNLOAD_THREAD_FLAG_PAUSED) & ~_DOWNLOAD_THREAD_FLAG_READY; return; } if (((_download_thread_flag & 0xffffff) & (_DOWNLOAD_THREAD_FLAG_START_REQUESTED | _DOWNLOAD_THREAD_FLAG_STARTED)) != 0) { //Tracer.GlobalTracer.TraceInfo("---PAUSED---"); _download_thread_flag |= _DOWNLOAD_THREAD_FLAG_PAUSE_REQUESTED; } else { return; } } _monitor_thread_created.Wait(); _monitor_thread.Join(); _monitor_thread_created.Reset(); } try { TaskPaused?.Invoke(this, new EventArgs()); } catch { } }
public void Pause() { lock (_external_lock) { lock (_thread_flag_lock) { //ready state if ((_upload_thread_flag & _UPLOAD_THREAD_FLAG_READY) != 0) { _upload_thread_flag = (_upload_thread_flag | _UPLOAD_THREAD_FLAG_PAUSED) & ~_UPLOAD_THREAD_FLAG_READY; return; } //status failure if ((_upload_thread_flag & (_UPLOAD_THREAD_FLAG_STARTED | _UPLOAD_THREAD_FLAG_START_REQUESTED)) != 0) { Tracer.GlobalTracer.TraceInfo("---PAUSED---"); _upload_thread_flag |= _UPLOAD_THREAD_FLAG_PAUSE_REQUESTED; } else { return; } _monitor_thread_created.Wait(); _monitor_thread_exited.Wait(); _monitor_thread_exited.Reset(); _monitor_thread_created.Reset(); } } try { TaskPaused?.Invoke(this, new EventArgs()); } catch { } }
private void _on_task_paused(object sender, EventArgs e) { try { TaskPaused?.Invoke(sender, e); } catch { } }