Wednesday, November 7, 2018

Problems breaking while debugging a MT call from worker thread

This is an obscure problem. It probably won't happen to you, but if it does - here's an explanation.

I am using WCF to call middle-tier code that can take a while to complete. To keep the users happy, I'm calling the middle tier from a worker thread, updating a database record periodically from the middle tier, and monitoring the database record and updating the UI from the UI thread. This all works very well.

But if I'm debugging in the middle tier and kill the process by clicking the Stop Debugging button, the thread completes instead of aborting and I can't debug on the MT any more (it doesn't hit any break points). I have to close and restart Visual Studio to be able to hit break points on the middle tier again.

This is similar to attaching to a process, for example when debugging a service. It occurs to me that Visual Studio may be using a similar process because I'm making the WCF call from a non-UI thread. When debugging a service you have to be sure to stop the debugger by clicking Terminate All from the Debug menu entry.

I tried clicking Terminate All while debugging my WCF service and everything worked correctly. The thread did not continue and I was able to hit break points on subsequent debug sessions.

No comments:

Post a Comment