ThreadPool. GetAvailableThreads (out int a1, out int a2); // a1 indicates the worker thread and a2 indicates the IO thread.
Jeffrey Richter's masterpiece CLR via C #
IHttpAsyncHandler{
Public byte [] bytes;
Public HttpContext context1;
{
Throw new Exception ();
}
Context1 = context;
// If the file size is smaller than the buffer value of 1024, the file will be read at one time, and the worker thread in the CLR thread will still be used for callback.
FileStream fileStream = new FileStream ("E: // My Webs/WebService1/TextFile.txt ",
);
Bytes = new byte [fileStream. Length];
Return fileStream. BeginRead (file1.bytes, 0, (int) fileStream. Length, callback, file1 );
// At this time, the worker thread in the CLR thread pool will be released in time. When reading is completed, the IO thread will be called again to complete the operation.
{File1.fileStream. EndRead (result );
File1.fileStream. Close ();
}
Get {
Return false;
}
}
- DNS operations:BeginGetHostByName and BeginResolve.
- Socket operation:BeginAccept, BeginConnect, and BeginReceive.
- WebRequest operation:BeginGetRequest and BeginGetResponse.
- SqlCommand operation:BeginExecuteReader, BeginExecuteNonQuery, and so on. This may be the most common Asynchronous Operation for developing a Web application. If you need to obtain IOCP support for database operations, you need to mark Asynchronous Processing as true (false by default) in the connection string. Otherwise, an exception will be thrown when the BeginXXX operation is called.
When asynchronous delegation is used (BeginInvoke, EndInvoke), the threads added by the system are also the worker threads in the CLR thread pool. If the asynchronous method is used numbly, it will be counterproductive, affects system performance.