Background Worker avec Do-While
Bonjour à tous,
j'essaye d'implémenter un background worker , pour avoir un sleep en tâche de fond (pour ne pas faire planter mon appli - "not responding").
J'ai une bouble while et j'aimerais vraiment attendre 10sec avant de passer à l'élément suivant. Mais cela ne fonctionne pas, le sleep(10000) n'est pas pris en compte... des idées ? :)
merci
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
do
{
returnCode = LaunchScript(FileName, strCommandMonitor);
// if success we break the loop
if (returnCode == 2)
{
break;
}
// wait 5sec
nbrAttempts++;
//timeout
// wait 10 sec with Background Worker
if (!(worker.IsBusy))
{
worker.RunWorkerAsync();
}
}
while (nbrAttempts < 10); |
Code:
1 2 3 4 5
| void worker_DoWork(object sender, DoWorkEventArgs e)
{
MessageBox.Show("test");
Thread.Sleep(10000);
} |