Steve Richter
2005-06-07 18:59:33 UTC
I dont get the point of socket.BeginReceive and socket.EndReceive. As I
understand it, BeginReceive will start a 2nd thread, call the
ReceiveCallback delegate in the 2nd thread, then block until the
socket.EndReceive method called in the 2nd thread receives some data
from the socket.
If the 1st thread will block until the 2nd thread receives some data
from the socket, what is the point of starting up the 2nd thread? I am
aware I can create my own thread and have the two threads behave the
way I want, but what am I missing about BeginReceive and EndReceive?
Is BR ... ER intended for situations when a lot of data is to be
received and EndReceive will return after the first block of data is
returned?
A 2nd related question ... How does the first thread kill the receive
in progress in the 2nd thread? Wait for the current chunk of data to
be received by EndReceive and use a sync object of some sort to signal
it is time for the 2nd thread to end?
3rd question ... the documentation says SetSocketOption -
ReceiveTimeout does not apply when Socket.BeginReceive is used. How do
I implement timeout when using the BeginReceive ... EndReceive pair?
thanks,
-Steve
understand it, BeginReceive will start a 2nd thread, call the
ReceiveCallback delegate in the 2nd thread, then block until the
socket.EndReceive method called in the 2nd thread receives some data
from the socket.
If the 1st thread will block until the 2nd thread receives some data
from the socket, what is the point of starting up the 2nd thread? I am
aware I can create my own thread and have the two threads behave the
way I want, but what am I missing about BeginReceive and EndReceive?
Is BR ... ER intended for situations when a lot of data is to be
received and EndReceive will return after the first block of data is
returned?
A 2nd related question ... How does the first thread kill the receive
in progress in the 2nd thread? Wait for the current chunk of data to
be received by EndReceive and use a sync object of some sort to signal
it is time for the 2nd thread to end?
3rd question ... the documentation says SetSocketOption -
ReceiveTimeout does not apply when Socket.BeginReceive is used. How do
I implement timeout when using the BeginReceive ... EndReceive pair?
thanks,
-Steve