Reputation: 5203
My application is in a deadlock. Is there any ways to identify the objects which are presently locked (as shown below)?
void DoWork()
{
lock(this._lockObj)
{
// Do some work
}
}
Upvotes: 2
Views: 1620
Reputation: 2650
If you're debugging under Visual Studio, it's not too hard. You'll need two debug windows in particular: Call stack and Threads. Pause the program, and then in the thread window double click on each thread, to find where it's currently stopped. The deadlocking threads should have their execution stopped on a "lock" statement.
Then, on each of the deadlocked threads, you can trace your way up the stack to find the other lock. Just double click each method on the call and look at the context until you find another lock that you're inside of.
Upvotes: 4
Reputation: 755357
The best way to do this is to use WinDbg and the SOS extension. It has a command named !SyncBlk
that provides just this information. Here is a link to a quick tutorial
Upvotes: 7