Pause/Resume loop in Background worker

前端 未结 1 441
醉酒成梦
醉酒成梦 2020-12-06 03:28

I have a loop in Background worker in a Winform Application.

I Just used this Code but it won\'t resume after the Pause.

In the main Class I use this

相关标签:
1条回答
  • 2020-12-06 03:51

    My best guess for what you want:

    void ResumeWorker() {
         // Start the worker if it isn't running
         if (!backgroundWorker1.IsBusy) backgroundWorker1.RunWorkerAsync(tempCicle);  
         // Unblock the worker 
         _busy.Set();
    }
    
    void PauseWorker() {
        // Block the worker
        _busy.Reset();
    }
    
    void CancelWorker() {
        if (backgroundWorker1.IsBusy) {
            // Set CancellationPending property to true
            backgroundWorker1.CancelAsync();
            // Unblock worker so it can see that
            _busy.Set();
        }
    }
    
    0 讨论(0)
提交回复
热议问题