简体   繁体   English

异步方法是否在单独的线程中运行?

[英]Do async methods run in separate thread?

My silverlight application is calling a webservice method asynchronously as follows: 我的Silverlight应用程序正在异步调用Webservice方法,如下所示:

 gServer = new ServiceReference1.Service1SoapClient();

 gServer.Retrieve_DataSet_ListCompleted += new EventHandler<ServiceReference1.Retrieve_DataSet_ListCompletedEventArgs>(Retrieve_Data_List_Completed);

Does Retrieve_Data_List_Completed method run in a different thread? Retrieve_Data_List_Completed方法是否在其他线程中运行?

The event handler will run in the thread that instantiated Gserver. 事件处理程序将在实例化Gserver的线程中运行。 The asynchronous bit is gServer beavering away gettimng the data on it's thread, when it's don it tells "your" thread it is. 异步位是gServer禁止获取线程上的数据,如果不这样做,它将告诉“您的”线程。

No thread will be running waiting for the result. 没有线程将在运行中等待结果。 Async webservice calls are entirely threadless. 异步Web服务调用完全是无线程的。 Everything down to the socket read and write operations happens using async methods. 套接字读取和写入操作的所有操作均使用异步方法进行。 The socket itself will queue the request to an IO completion port which is a Windows kernel primitive. 套接字本身会将请求排队到IO完成端口,该端口是Windows内核原语。

Only when the result is available your callback will be invoked on some random thread. 只有当结果可用时,您的回调才会在某个随机线程上被调用。 But this thread did not need to be there all the time. 但是该线程并不需要一直存在。 It is taken from the thread-pool. 它是从线程池中获取的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM