Pausar / retomar loop no trabalhador em segundo plano
Tenho um loop no trabalhador em segundo plano em um aplicativo Winfor
Acabei de usar esteCódig mas não será retomado após a Pausa.
Na classe principal eu uso este
System.Threading.ManualResetEvent _busy = new System.Threading.ManualResetEvent(false);
Then in My Start Clique em que escrevi:
if (!backgroundWorker1.IsBusy)
{
MessageBox.Show("Not Busy"); //Just For Debugg
_busy.Set();
Start_Back.Text = "Pause";
backgroundWorker1.RunWorkerAsync(tempCicle);
}
else
{
_busy.Reset();
Start_Back.Text = "Resume";
}
btnStop.Enabled = true;
Em seguida, em backgroundworker doWork eu escrevi isso:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
m_addTab addTabsInvoke = addTabUrl2;
Invoke(addTabsInvoke, "http://www.google.com");
foreach (something)
{
_busy.WaitOne();
if (backgroundWorker1.CancellationPending)
{
return;
}
if (tabs.InvokeRequired)
{
......
......
Não consigo entender por que a pausa funciona enquanto o currículo não funciona. Eu errei alguma coisa?