.NET Matters: Deadlock monitor

A reader asks:

I'm using locks in my application to synchronize work on a bunch of threads. Unfortunately, I'm doing something incorrectly and my threads seem to just stop sometimes. I think I'm running into deadlocks, but I'm not sure how to find them. Is there any way I can do so programmatically? I'd like an exception to be thrown when a deadlock is encountered.

In the October issue of MSDN Magazine, Stephen Toub answers this question by explaining how deadlocks occur, then building a sample DdMonitor class that wraps the .NET System.Threading.Monitor class and includes deadlock detection capabilities.

Don't forget to browse the code online to explore the DdMonitor class further.

For more of Stephen's writing on .NET development, check out the .NET Matters archive on the MSDN Magazine web site.

Happy coding!

Terrence Dorsey

Skip to main content