How can I find out the resources occupied by a .NET thread?

I am developing a multi-threaded application and one of my threads is somehow blocked by something and thus it will take up some resource like a file forever. Is there a way to find out which thread is blocked, and more importantly, which resource is being held by that thread?

Finally and as usual, thanks for your patience and your response. :)

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

Because all resources on the Windows platform are accessible through "handles". I wonder if there is a way to list all the handles that the .NET stream supports?

+2


a source to share


3 answers


When creating threads, you can set a name for each thread just before starting it. Then you can use them in Debugger to identify the thread in question.

Then when your program doesn't close, you go to the debugger and hit pause, then you can activate the active threads. Debug-> Windows-> Threads (CTRL-ALT + H)



If your threads are not critical and you just want the system to shut down upon completion, you can set .IsBackground on the thread and you don't need to do any special operations to close the thread, often this can lead to other conditions that you don't expected.

I personally also use System.Threading.AutoResetEvent(duration)

instead Sleep(duration)

, because if I want to exit, I set mIsRunning=false

and then set an event that will cause the event to stop to wake up, but will exit immediately. The dream must end before it can resume.

+1


a source


The new Concurrency Profiler in Visual Studio 2010 was created to answer and resolve this issue.

Resource Conflict Concurrency Profiling in Visual Studio 2010 - Performance Research Threads



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

0


a source


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

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

0


a source







All Articles