473,386 Members | 1,766 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,386 software developers and data experts.

How to cancel a BackgroundWorker in a blocked state ?

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
2 6686
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
2
by: Steve | last post by:
After running into a design wall with my traditional thread approach, I realized that a BackgroundWorker object would fit my needs pretty good. Never really used them before. In a nutshell, my...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
1
by: David Veeneman | last post by:
Does anyone knmow why an asynchronous worker method would crash if the e.Cancel method is set to true, but not otherwise? I'm working on a demo app with an asynchronous call, using the .NET 2.0...
7
by: =?Utf-8?B?SGVucnk5OQ==?= | last post by:
What happens here? The backgroundworker (bgw) unzips RTF-Helpfiles (up to 1 MB in size). The ProgressChanged-Event gets the unzipped files (to display them in a RichtTextBox) It follows the...
3
by: vulpes | last post by:
How do I implement the "incremental results" with a BackgroundWorker? Many pages, http://msdn2.microsoft.com/en-us/library/wewwczdw.aspx for example, tell that I should subclass the...
3
by: Coaster | last post by:
I want to create a "thread manager" class to manage an array of backgroundworkers. I'd like this thread manager class to live in a class library and I wasn't sure if it was possible to make the...
16
by: parez | last post by:
I start a BackGroundWorker to populate a grid. It is started off in the ui layer The thread follows( cannot think of a better word) the path UI->Layer1->Layer2->Communication Layer and it...
7
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
How do you cancel a BackgroundWorker? For this BackgroundWorker: bgWorker.WorkerReportsProgress = true; bgWorker.WorkerSupportsCancellation = true; I have tried this, but it never exits the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.