C# Asynchronous Sockets questions.

Posted by ccppjava on Stack Overflow See other posts from Stack Overflow or by ccppjava
Published on 2010-03-15T12:17:34Z Indexed on 2010/03/15 12:19 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

Based on my reading and testing, with asynchronous sockets, the socket itself can be passed using state object (IAsyncResult result), also if store the socket as a private field, it would be captured by the callback methods.

I am wondering how the IAysnResult is kepted between the BeginXXX and ReceiveXXX? It looks to me that after the BeginXXX call and the method ends, the state object would be disposed by GC if there is no reference to it.

In the case of private field, how the private field is shared between threads? (As far as I know, a callback is executed using a thread from the default thread pool, which would be considered as a new thread.)

Many thanks, hope the questions themselves are clear.

© Stack Overflow or respective owner

Related posts about c#

Related posts about sockets