Event model

  • Thread starter Thread starter ryanm
  • Start date Start date
R

ryanm

I have a class with a non-blocking client socket open, but I don't want
to poll it for data, I want to raise an event when data arrives. Is that
possible, or does the Receive method have to be polled in order to know when
there is new data? The socket doesn't appear to have any events of it's own,
from looking at the docs. Is there some way to tell when new data arrives,
or do I have to ask the socket?

ryanm
 
ryanm,

Usually, in situations like this, a thread is dedicated to reading from
the socket, blocking on that thread, and then responding when data arrives.
I would recommend you do something similar.

If creating a thread doesn't appeal to you, then you should look into
calling the asynchronous Read methods (i.e. BeginRead, EndRead). This will
begin the call to read on another thread, and has the ability to notify you
via an event when that read operation is complete.

Hope this helps.
 
Back
Top