title: Patterns for Multithreaded Network Server in C#
body: <p>Are there any templates/patterns/guides I can follow for designing a multithreaded server?  I can't find anything terribly useful online through my google searches.</p>
  
  <p>My program will start a thread to listen for connections using TcpListener.
  Every client connection will be handled by it's own IClientHandler thread.  The server will wrap the clientHandler.HandleClient in a delegate, call BeginInvoke, and then quit caring about it.</p>
  
  <p>I also need to be able to cleanly shutdown the listening thread, which is something I'm not finding a lot of exampes of online.</p>
  
  <p>I'm assuming some mix of lock/AutoResetEvents/threading magic combined with the async BeginAceptTcpClient and EndAcceptTcpClient will get me there, but when it comes to networking code, to me it's all been done. So I have to believe there's just some pattern out there I can follow and not get totally confused by the myriad multithreaded corner cases I can never seem to get perfect.</p>
  
  <p>Thanks.</p>