prolion
 1 private readonly ManualResetEvent _resumeEvent = new ManualResetEvent(false);        
 2 private volatile bool _blnPaused; //记录运行状态是否暂停
 3 
 4         /// <summary>
 5         /// 暂停
 6         /// </summary>
 7         public void Pause()
 8         {
 9             _resumeEvent.Reset();
10             _blnPaused = true;
11         }
12 
13         /// <summary>
14         /// 重启
15         /// </summary>
16         public void Resume()
17         {
18             _blnPaused = false;
19             _resumeEvent.Set();
20         }
21 
22 ...
23 
24 线程方法中添加下面的代码
25 
26           if (_blnPaused) //如果暂停则等待
27           {
28              _resumeEvent.WaitOne();
29           }
30           else
31           {
32

 

分类:

技术点:

相关文章:

  • 2021-12-30
  • 2021-12-12
  • 2021-12-12
  • 2021-12-22
  • 2021-12-12
  • 2022-02-08
  • 2021-12-12
  • 2021-12-12
猜你喜欢
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
  • 2021-08-31
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
相关资源
相似解决方案