I've written a network server application from scratch, so no IIS or Windows Form. I have been using Task.Run to hand off control over the life of a network session to run in the background.
Something like...
while (true)
{
var tcpClient = tcpListener.Accept...
Task.Run(() => ProcessSession(tcpClient));
}
...and then...
public async Task ProcessSession(TcpClient tcpClient)
{
...
await tcpClient.GetStream().ReadAsync(...)
...
}
My hope was that when I did async / await with the network I/O in ProcessSession that the worker thread would get freed up until the I/O completed.
I'm finding that my server software is getting bogged down with only a few hundred connections, to the point where clients timeout trying to connect, or if they get connected that they have really slow network throughput. I was hoping to handle many thousands of connections per server.
When I look at ThreadPool.Get(Max/Available)Threads, it doesn't look like much is going on there. Process.GetCurrentProcess().Threads.Count is only in the low dozens, so it's not like it's a thread per connection. It's just bogged down.