Gracefully exiting blocking or asynch socket receive

G

Guest

I am writing a server component that will raise various "events" using UDP
multicast events. A number of winform clients will begin receiving these
events on a background thread, listening on the muticast address.

My question is, is there a way of shutting down these threads without
calling Thread.Abort, e.g. when the user shutsdown the application.

If I use the async BeginReceiveFrom method, I still have to call
EndReceiveFrom to ensure I do not leak resources. However, this will block,
and there is no timeout option. I did consider sending a "terminate" event to
the socket, but then realised this would be sent to the multicast address,
and so to all the other listening clients.

The only option I see is to store a refence to the listening thread, and
call Abort on it when I want to shutdown, and trap the resulting exception.

Any alternative suggestions appreciated.

Dan
 
G

Guest

Hi,

If you want your threads to be disposed when the application finishes set
the property IsBackground to True on each thread.

Best regards
Salva
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top