I have a backgroundworker with a recursive method in the Do_Work Method. If an exception occurs in the revursive method, then i am not able to catch that exception. I have already tried getting it trough the RunWorkerCompleted Event, but that doesn't work either.
Backgroundworker
var worker = new BackgroundWorker();
worker.DoWork += Do_Work;
worker.RunWorkerCompleted += Work_Completed;
worker.WorkerReportsProgress = true;
worker.ProgressChanged += ProgressChanged;
worker.RunWorkerAsync();
Do_Work Method
public void Do_Work(object sender,DoWorkEventArgs e)
{
for(int i = 0;i<10;i++)
{
RecursiveMethod();
}
}
Ive tried putting try catches around pretty much everything. And ive tried getting the exception from the completed event.
public void Work_Completed(object sender, RunWorkerCompletedEventArgs e)
{
if(e.error != null){Do_Something()}
}
When i run my code i dont get to the work completed event. If any exception occurs in the recursive method my application stops. Does anyone know why this is happening and how to prevent this?