views:

50

answers:

3

Hi guys!

I am developing a multi-thread application and one of my threads is somehow blocked by something and thus it will occupy some resource such as a file forever. Is there a way to find out which thread is being blocked and more important what resouce is being held by that thread?

At last and as usual, thanks for your patience and reply. :)

---------new progress----------

Since all the resouces on the windows platform are accessed via "handles". I am thinking if there is a way to list all the handles a .NET thread is holding?

A: 

The new Concurrency Profiler in Visual Studio 2010 was built to answer and solve this type of question.

Resource Contention Concurrency Profiling in Visual Studio 2010 – Performance Investigation Flows

I recommend downloading the trial version if you don't already have Visual Studio 2010. You won't be disappointed. :)

280Z28
+1  A: 

When you Create the Threads, you can Set a Name for each thread just before you start it. You can then use these in the Debugger to identify the Thread in question.

Then when your program doesn't close, you jump up to the debugger and Hit Pause, you can then via the active threads. Debug->Windows->Threads (CTRL-ALT+H)

If your threads are not critical, and you just want the system to Close upon Completion you can set .IsBackground on the thread and you don't need to perform any special operations to get your thread to close, often though this may lead to other conditions you were not expecting.

I personally also use System.Threading.AutoResetEvent(duration) instead of Sleep(duration) because if I wish to exit, I set "mIsRunning=false" then set the event which will cause the Stopping of the Event to Wake up, but Exit Immediately. A Sleep has to finish before it resumes.

Paul Farry
A: 

If you are familiar with dump analysis using WinDbg, you can also capture a hang dump when this issue happens, and then manually analyze the dump to see which thread hangs and why.

http://blogs.msdn.com/tess/archive/tags/Performance+issues+and+hangs/default.aspx

Lex Li