BackgroundWorker acting bizarrely...
- by vdh_ant
Hi guys
I'm working on some code that calls a service. This service call could fail and if it does I want the system to try again until it works or too much time has passed.
I am wondering where I am going wrong as the following code doesn't seem to be working correctly... It randomly only does one to four loops...
protected virtual void ProcessAsync(object data, int count)
{
var worker = new BackgroundWorker();
worker.DoWork += (sender, e) =>
{
throw new InvalidOperationException("oh shiznit!");
};
worker.RunWorkerCompleted += (sender, e) =>
{
//If an error occurs we need to tell the data about it
if (e.Error != null)
{
count++;
System.Threading.Thread.Sleep(count * 5000);
if (count <= 10)
{
if (count % 5 == 0)
this.Logger.Fatal("LOAD ERROR - The system can't load any data", e.Error);
else
this.Logger.Error("LOAD ERROR - The system can't load any data", e.Error);
this.ProcessAsync(data, count);
}
}
};
worker.RunWorkerAsync();
}
Cheers
Anthony