是否ExecuteRegisteredAsyncTasks释放请求处理线程用于其它请求?线程、ExecuteRegisteredAsyncTasks

2023-09-06 05:04:24 作者:超记仇

我注意到,code从的 ExecuteRegisteredAsyncTasks 调用此调用之前在同一个线程中code执行。所以我的理解是手动调用 ExecuteRegisteredAsyncTasks 不会释放请求处理线程用于其它请求,并且此方法只应该自动调用以获取扩展好处?

I noticed that code after return from ExecuteRegisteredAsyncTasks call is executed in same thread as code before this call. So I understand that manually calling ExecuteRegisteredAsyncTasks doesn't free the request-processing thread to service other requests and this method should be only automatically called to get scaling benefit?

在MSDN的例子code,但帮助不会回答这个问题。

On msdn is example code but help doesn't answer this question.

更新

在我的情况下,在 PageAsyncTasks 我异步调用Web服务(使用开始*和结束*),所以我没有使用线程池。

In my case, in PageAsyncTasks I am asynchronously calling web services (using Begin* and End*) so I am not using thread pool.

推荐答案

RegisterAsyncTask 方法的MSDN的例子,他们只是声明了一个 AsyncTaskDelegate 它被调用,开始和结束的方法。当你异步调用一个代表,它使用一个线程的线程池,所以你基本上没有得到在这种情况下,任何的改善。唯一速度的提高可能是,如果你是并行执行多个操作,否则会被同步执行。

In the MSDN example of the RegisterAsyncTask method, they simply declare an AsyncTaskDelegate which is invoked with Begin and End methods. When you asynchronously invoke a delegate it uses a thread from the thread pool so you are basically not getting any improvement in this case. The only speed improvement might be if you were executing multiple operations in parallel that would otherwise would be executed synchronously.

。它们适于I / O密集​​型任务,例如网络电话(数据库调用,web服务调用,...)。不适合CPU密集型任务。因此,让我们假设你想使用 Web客户端执行HTTP调用.DownloadStringAsync 方法。此方法不从线程池使用一个线程。它注册一个IOCP的内核,并触发HTTP请求。当它返回控制,没有线程正在消耗的来电,这整个HTTP请求的持续时间内。一旦请求完成IOCP的指示和一个线程从线程池处理结果绘制。

If you want to get a real performance boost you need to use IOCP (I/O Completion Ports). They are adapted to I/O intensive tasks such as network calls (database calls, web service calls, ...). Not suitable for CPU intensive tasks. So let's suppose that you want to perform an HTTP call using WebClient.DownloadStringAsync method. This method doesn't use a thread from the thread pool. It registers an IOCP with the kernel and fires the HTTP request. When it returns control to the caller no thread is being consumed and this during the whole HTTP request duration. Once the request finishes the IOCP is signaled and a thread is drawn from the thread pool to process the results.

看看的异步页。 IOCP解释更好。

Take a look at the asynchronous pages in ASP.NET article. IOCP are explained better there.