Regarding asynchronious sockets
, I would like to know if its possible to hold the thread, before all the data are sent?
With use of Socket.BeginSend
public IAsyncResult BeginSend(
byte[] buffer,
int offset,
int size,
SocketFlags socketFlags,
AsyncCallback callback,
Object state
I send data inside buffer parameter. I would like to know if is it possible to block the thread some how before all data are really sent from here (without regarding if data are received on the other side)? So I can call a Socket.BeginReceive
method?
--
Will it be good enough to use a ManualResetEvent
delegate (I called it "sendDone")?
Example:
private static ManualResetEvent sendDone = new ManualResetEvent(false);
//inisde a method call WaitOne() method:
sendDone.WaitOne();
Is this good enough? Or are there any better alterantives?
thx for the ans
The easiest way is to use the
Send
method on theSocket
class, as it blocks the calling thread, like so:Note that if you really wanted to block on the call to BeginSend, you can use the Task Parallel Library to create a
Task<TResult>
which you can then wait on, like so: