By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

How to cancel a BackgroundWorker in a blocked state ?

P: n/a
The backgroundworker contains a blocking call to UDPClient.Receive

How do i unlock this thread so the backgroundworker can be cancelled ?

Johan
May 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Johan,

I would call Dispose on the UdpClient. This will dispose of the client,
and probably shut down the socket.

You will have to prepare for this in your thread, as the Receive method
will probably throw.

Why are you blocking on Receive? Why not call BeginReceive and pass a
callback to it to be informed when it returns? This way, you don't have to
block a thread. It would be much more efficient.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
The backgroundworker contains a blocking call to UDPClient.Receive

How do i unlock this thread so the backgroundworker can be cancelled ?

Johan

May 11 '06 #2

P: n/a
thanks for the hint.

I got rid of the worker and switched to the async callback. ,works ok.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uc**************@TK2MSFTNGP05.phx.gbl...
Johan,

I would call Dispose on the UdpClient. This will dispose of the client, and probably shut down the socket.

You will have to prepare for this in your thread, as the Receive method will probably throw.

Why are you blocking on Receive? Why not call BeginReceive and pass a
callback to it to be informed when it returns? This way, you don't have to block a thread. It would be much more efficient.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
The backgroundworker contains a blocking call to UDPClient.Receive

How do i unlock this thread so the backgroundworker can be cancelled ?

Johan


May 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.