One of our Windows Forms applications has had a strange problem for several months. The application worked very reliably for most of our customers, but on some PCs (mainly with wireless LAN), the application sometimes just didn’t respond anymore. (You click on the user interface, and windows require you to wait or kill the application).
For a long time I could not track the problem, but now I understood what had happened. The application had this line of code
// don't blame me for this. Wasn't my code :D Control.CheckForIllegalCrossThreadCalls = false
and used some background threads to change the controls.
Not. I found a way to play the application stopping the response error on my dev machine and tracked it down to the line where I actually used Invoke () to run the task in the main thread.
Me.Invoke(MyDelegate, arg1, arg2)
Obviously there is a thread block somewhere. After uninstall
Control.CheckForIllegalCrossThreadCalls = false
and refactoring the entire program to use Invoke () when changing a control from a background thread, the problem (hopefully) is gone.
However, I am wondering if there is a way to find such errors without debugging every line of code (even if I broke into the debugger after the application stops responding, I can’t say what happened last because the IDE doesn’t go to the expression Invoke ())
In other words:
If my applications freeze, how can I figure out which line of code was last executed?
Perhaps even on PC clients.
I know that VS2010 offers some debugging feature back, maybe this will be a solution, but I am currently using VS2008.
Jürgen steinblock
source share