I'm may be just misunderstanding something fundamental here but...
我可能只是误解了一些基本的东西,但......
Senario: I call System.Net.Sockets.NetworkStream
's BeginRead
method and my machine receives a response/request from a network device. The runtime runs my callback in its own thread. Before this thread can call EndRead
, the machine receives another response/request.
Senario:我调用System.Net.Sockets.NetworkStream的BeginRead方法,我的机器从网络设备接收响应/请求。运行时在自己的线程中运行我的回调。在此线程可以调用EndRead之前,机器会收到另一个响应/请求。
Question: Will the runtime call my callback in another thread immediately or wait for me to call EndRead
and then BeginRead
again?
问题:运行时是否会立即在另一个线程中调用我的回调或等待我再次调用EndRead然后调用BeginRead?
2 个解决方案
#1
It should run the callback method immediately in another thread. (hence the asynchronous rather than blocking calls).
它应该在另一个线程中立即运行回调方法。 (因此是异步而不是阻塞调用)。
#2
You have to call EndRead and then BeginRead again to handle the new incoming message.
您必须再次调用EndRead然后再调用BeginRead来处理新的传入消息。
#1
It should run the callback method immediately in another thread. (hence the asynchronous rather than blocking calls).
它应该在另一个线程中立即运行回调方法。 (因此是异步而不是阻塞调用)。
#2
You have to call EndRead and then BeginRead again to handle the new incoming message.
您必须再次调用EndRead然后再调用BeginRead来处理新的传入消息。