Welcome to RightHand's community place Sign in | | Help

Problems debugging BackgroundWorker and solution

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:

  1. No more calls into ToString()
  2. Disable func eval entirely (ouch)
  3. 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.

Published 23. december 2005 14:38 by Miha Markic
Filed under:

Comments

# re: Problems debugging BackgroundWorker and solution

20. april 2006 14:48 by David Connolly
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,








# re: Problems debugging BackgroundWorker and solution

20. april 2006 14:50 by David Connolly
oops- overriding ToString() was metioned in the other blog post, sorry.

# re: Problems debugging BackgroundWorker and solution

21. april 2006 9:03 by Miha Markic
Hi David,

Yes, that is one way to go. However, sometimes you don't have the luxury to do it for various reasons.

# Debug Probleme | hilpers

20. januar 2009 16:37 by Debug Probleme | hilpers
Anonymous comments are disabled