The code runs correctly for a few hour then fail before running again for a few hour...
The project is an web application with WCF service, running on IIS. The BGW is started on Application.Start()
I'm suspecting its because of IIS recycling. Is my approach wrong? how can i make the BGW runs reliably
public void MyWorks()
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerSupportsCancellation = true;
worker.DoWork += new DoWorkEventHandler(DoWork);
worker.RunWorkerAsync();
}
private static async void DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
int delay = 60;
while (!worker.CancellationPending)
{
await Task.Delay(TimeSpan.FromMinutes(delay));
//do things here
}
}