[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 815
  • Last Modified:

Thread Termination and UDP Socket Release Problem in VB.NET

I have a UDP Listen Class with a standard Thread procedure that includes a blocking call:

     BytesReceived = udpSocket.ReceiveFrom(Buffer, RemoteEndPoint)

My question is how do I shut down this Thread and Socket properly, I've tried


but this raises a System.Threading.ThreadAbortException: Thread was being aborted, error presumably as the socket receive is still blocking? Although it does release the udp port for me to connect again. Is there a neater way to shutdown?
1 Solution
I would not suggest using the blocking method with a thread instead you can use the BeginReceiveFrom method to receive .. then use Socket.Close ... your handler will get called and can realize it has no data.
mrflibbleukAuthor Commented:
Ok thanks, reworked it using waitany on the the async handle and a thread termination event.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now