473,698 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 BeginReceiveFro m 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 1792
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 BeginReceiveFro m 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
3890
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 support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or
4
4351
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 sequence with a server: connect write(50 bytes) read(2002 bytes) write(50 bytes) read(2002 bytes)
3
3697
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 tried this I don't see any diffents, I am sending 10Mb and the Send/BeginSend command doesn't wait till the data is on the remotepoint. Can somebody pls. explain this. Regards Robert.
2
12671
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 under the Compact Framework, which does not support Abort. Will Socket.Close cause the Receive method to finish, or is there a better way?
6
4111
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: Connect Receive response Send Connect ACK
0
1705
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 IPEndPoint(IPAddress.Parse(ip),portNum); oSocket.Blocking=false; oSocket.Connect(endPoint); ..... while (CountinueThread) {
1
4300
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 block. On my TCPListener I just check intermittently for a connection using pending. This allow it to be non blocking. Is there a way to do this with Receive?
4
12794
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. Is this the correct behavior? My MSDN documentation led me to believe that this function should block until at least 1 byte of data was available, the connection was closed, or size bytes of data had been read. Any comments or clarifications...
23
5704
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() { : : do stuff
0
8678
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.