473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Gracefully exiting blocking or asynch socket receive

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
Nov 17 '05 #1
1 1778
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
"Dan Kelley" wrote:
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
4
by: Christopher H. Laco | last post by:
I'm having a problem with the TcpClient that I can only conclude is either a feature, or a complete misunderstanding of the docs on my part. In a nutshell, I'm simply performing the following...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
0
by: user | last post by:
Hello I have socket: System.Net.Sockets.Socket oSocket = new Socket(IPAddress.Any.AddressFamily,SocketType.Stream,ProtocolType.Tcp); IPEndPoint endPoint = new...
1
by: Dave | last post by:
I'm using the following statement to receive info from a TCPListener socket, Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0); It works fine but it blocks. I need the receive to not...
4
by: Cyron | last post by:
Hello Friends, When I make a call to NetworkStream.Read(byte buffer, int offset, int size) I have found that this method will block until size bytes have been read or the connection is closed. ...
23
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.