c# - Dude, where's my thread?? (or: rename a .NET thread pool thread - is it possible?) -


Sometimes I proceed myself through an application in debug mode, as long as I'm on a particular line Do not hit 'step' and take it very well, doing a lot of time, doing a 100% CPU, at this point, I hit the 'break' button and tried to figure out what is going on so long Taking

The problem is that there is a huge amount of thread running in this app, and when I ' If I hit 'A', then the execution point goes to the GUI thread, which is probably just 'waiting', I have to hunt through the existing thread (I count them - this time they are 37!) I'm going on Was trying to find him. I have to find the stack of each one of them until I should find what I was looking for.

The thread I am running is an async call, so this thread runs on a thread pool. I want to give this thread a descriptive name and reset its name at the end of the operation.

The problem is that, property threads. The name can only be set once , later it returns a invalid operation expiration .

Any suggestions?

Oh, yes, I'm running VS2005 / .NET 2.0 but I'm also curious if newer versions have better ways to handle it.

Define the property of your own thread

  public class Thread Marker: IDisposable {[ThreadStick] Private Static String __Name; Fixed dictionary & lt; Int, string & gt; Threadname = new dictionary & lt; Int, string & gt; (); Public Static Name {get {return __Name;}} Public Threadmoker (String Name) {Lock (Threadname) {Thread Name [Thread Present. } __ name = name; } Public Zero () {ThreadNames.Remove (Thread.CurrentThread.ManagedThreadId); __Name = "unauthorized"; }}  

You can also write your own cover which automatically uses your action / delegation / async callback in this statement.

  class NamedHandler & lt; TArg & gt; {Public readonly action & lieutenant; Tag & gt; Handler; NamedHandler (String Name, Action & Lt; TARG & gt; Handler) {Handler = ARG = & gt; {(New Threadmaker (name)) {Handler (RGR); }}}} Uses zero dustfood (string agr) {log ("thread {0}" stu, threadtaker. Name); } ThreadPool.QueueUserWorkItem (new name given handler  ("my thread", arg = & gt; dstf (rarg)) handler);  

Then, when you stop the debugger, take a look at the contents of the variable threadmaker. Thread name and you will see which managed threads are stuck in handlers in your name.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -