473,805 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to cancel a BackgroundWorke r in a blocked state ?

The backgroundworke r contains a blocking call to UDPClient.Recei ve

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

Johan
May 11 '06 #1
2 6703
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.co m

"Sagaert Johan" <RE************ *@hotmail.com> wrote in message
news:eG******** ******@TK2MSFTN GP02.phx.gbl...
The backgroundworke r contains a blocking call to UDPClient.Recei ve

How do i unlock this thread so the backgroundworke r 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.c om> wrote in
message news:uc******** ******@TK2MSFTN GP05.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.co m

"Sagaert Johan" <RE************ *@hotmail.com> wrote in message
news:eG******** ******@TK2MSFTN GP02.phx.gbl...
The backgroundworke r contains a blocking call to UDPClient.Recei ve

How do i unlock this thread so the backgroundworke r 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
4942
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 terminate this thread by calling the "Abort" funcion. But the thread does not terminate and after the form is closed this thread keeps running at blocked state. Basically the application keeps running because this thread does not terminate while...
2
5401
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 problem is cancelling the worker. I've read the MSDN docs, checked google and haven't found a solution. The problem is, once I make a call to cancellAsync() (I check for CancellationPending in my DoWork handler) and WorkerComplete fires, the...
5
14135
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
1
6728
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 BackgroundWorker component. The app works fine if I let the worker method proceed to completion. But if I cancel the worker method, it crashes. Specifically, if I set the DoWorkEventArgs.Cancel property to true, the worker thread crashes at the...
7
1753
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 Trace that prints always what bgw has unzipped and what ProgressChanged received: 1. bgw: HelpFilelistgzip 2. ProgressChanged: HelpFilelistgzip OK!
3
4829
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 ProgressChangedEventArgs class, but what else? I haven't found any examples. (Why aren't there any?) Right now I have derived my own version of ProgressChangedEventArgs with some extra properties, declared
3
1841
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 thread manager a subclass of the backgroundworker so that I could start it up and still do other things on the client. Essentially a thread that spins off new threads. Am I going to hit any limitations here? thank you
16
2441
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 blocks (the server is executing somthing where which takes time)
7
4809
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 do...while loop: if (bgWorker.IsBusy == true) {
0
9718
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
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10368
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
10107
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...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
3
3008
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.