Did you ever set a breakpoint within BackgroundWorker execution (worker thread), hit it and then application would stall. It is certainly a strange behavior.
Apparently the problem happens because debugger calls into ToString() of the BackgroundWorker’s host (which is usual a Form derived class) and this call doesn’t happen in the same thread as host was created (remember, never touch UI controls from non-creation threads). This situation yields unpredictable results, normally application just doesn’t respond anymore. The cause and the workarounds to this annoyance is described in this blog post. Basically you have three possibilities:
- No more calls into ToString()
- Disable func eval entirely (ouch)
- Avoid the problem
I choose to go with the point 1. and it works for me. Point 2 is the worst choice.
I hope that debugger folks will do something regarding this issue in the future as it makes you wonder what is going on until you find the description.
If you make the ToString() method of the BackgroundWorker’s parent Form atomic, it seems this unpredicatibilty no longer occurs.
I put something like this in forms:
public override string ToString()
{
return “Disabled due to func-eval bug”;
}
Cheers,
oops- overriding ToString() was metioned in the other blog post, sorry.
Hi David,
Yes, that is one way to go. However, sometimes you don’t have the luxury to do it for various reasons.