Typically when you spawn a new thread, you want to give it a name to facilitate debugging. For example:
//.. other stuff....
Thread thread = new Thread(new ThreadStart(DoSomething);
thread.Name = "DoingSomething";
The code in the method DoSomething (not shown) will run on a thread named "DoingSomething."
Now suppose you're writing a socket server using the asynchronous programming model. You might write something that looks like the following:
ManualResetEvent allDone = new ManualResetEvent(false);
public static void Main()
Socket socket = new Socket(...); //you get the idea
socket.BeginAccept(new AsyncCallback(OnSocketAccept), socket);
public void OnSocketAccept()
Thread.CurrentThread.Name = "SocketAccepted";
// Some socket operation.
In the example above, we're setting up a...