When I call BeginSend on a socket, I pass a delegate which will be called (by a different thread) when the data has been sent.
What would happen if I call BeginSend anot
Based I what I read here, it seems like having multiple concurrent BeginSend
is do-able.
Excerpt:
- You can queue multiple BeginSends at the same time. YOu don't need to lock
- If you don't create a callback method, how do you know when the send is successful? You may want to ignore the success - more like a fire and forget - method, but then you at least need to know when it is safe to end your program.
- The other thing you can do is use the IAsyncResult that you get from BeginSend. You can use the WaitHandle to wait for the operation to complete. But that defeats the whole purpose of using Async in the first place.
- My recommendation is to use a callback, and make sure that the callback is called and the number of bytes you sent is actually sent and gracefuly end the send operation.
Update:
Tried simultaneous BeginSend
based on the codes on MSDN and data are sent without exception. However do keep in mind that the connection for the same socket must be opened prior. Simultaneous BeginConnect
will not work.