private void actionWorker_DoWork(object sender, DoWorkEventArgs e)
{
Action functionToRun = (Action)e.Argument;
ActionTask = Task.Factory.StartNew(() =>
{
int executionCount = 0;
while (executionCount < 3)
{
executionCount++;
try
{
Log.WriteVerbose(new SourceInfo(), "Started Background Worker action.");
ActionTaskThread = Thread.CurrentThread;
functionToRun();
break;
}
catch (ThreadAbortException)
{
TaskCancelled = true;
break;
}
catch (ClientRequestException cre)
{
if (cre.Message.Contains("The data is not available. The query may not have been executed."))
{
Log.WriteWarning(new SourceInfo(), "Exception Caught. Retrying... \r\nEx:{0}", cre.Message);
continue;
}
else
{
Log.WriteError(new SourceInfo(), "Exception Caught. \r\nEx:{0}", cre.Message);
break;
}
}
}
Log.WriteVerbose(new SourceInfo(), "Completed Background Worker action.");
});
while (!ActionTask.IsCompleted)
{
Thread.Sleep(500);
BackgroundWorker statusWorker = (BackgroundWorker)sender;
statusWorker.ReportProgress(0, AnimateText);
}
}