I work on a Comet application written in ASP.NET. There is an array of active connection contexts (HttpContext). And there is a thread that should periodically iterate through the collection and check theirs state. So application architecture is not thread-per-request.
What is the best way to check that a connection is active (not closed by the remote host)?
I found this:
context.Response.Write(' ');
context.Response.Flush();
if (!context.Response.IsClientConnected)
{
// ...
}
But it's not a good solution because it takes a thread time to process (Flush() is blocking operation). I need solution that works very fast for many concurrent connections and don't use blocking operations.
Maybe there is some IIS or ASP.NET functionality that allows to monitor connections this way?