I have the lock keyword in my code. It freezes because something else has the stuff loc开发者_运维知识库ked. Is there some sort of command or utility I can use to see who or what?
You can attach to the process with windbg and use sosex.dll to see what threads are deadlocked with the dlk command.
http://www.stevestechspot.com/SOSEXV40NowAvailable.aspx
If you are using lock, then you should be using it on an object you control. Usually, this is a dummy object only used for your locks i.e.
Object lockObj = new Object();
//some code
void MyCoolFunc()
{
lock(lockObj)
{
//do some not threadsafe stuff
}
}
Unfortunately, there is no simple answer ... but you can use tools such as CHESS to help you along the way. Ultimately, you will probably have to examine your code for race conditions that could result in deadlocks. Any place that you see a lock statement or other thread sync object (such as Monitors, Mutex, etc.) you will want to examine to see what they are locking on and find the other pieces of code that lock on the same thing
I think that you can use VS.NET to attach to the hung process and click the pause. Then invoke the Threads window (Debug-->Windows-->Threads) and check which threads are locked and why. This looks to be the easiest solution.
精彩评论