473,796 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RunWorkerComple tedEventArgs.Ca ncelled always false, even when I know it caught the cancel request

After running into a design wall with my traditional thread approach, I
realized that a BackgroundWorke r 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
CancellationPen ding in my DoWork handler) and WorkerComplete fires, the
value of Cancelled in the event args is always false.

Here is my code:
<code>

public void UpdateView()
{
if(MSP430Progra mmer.TargetConn ected())
{
View.CloseViewW ithResult(Dialo gResult.OK);
}

View.SetMessage Text(ProgramTar getResources.Ta rgetDisconnecte dMessage);

_pollingWorker = new BackgroundWorke r();
_pollingWorker. WorkerSupportsC ancellation = true;
_pollingWorker. DoWork += OnPollingWorker DoWork;
_pollingWorker. RunWorkerComple ted += OnPollingWorker Complete;
_pollingWorker. RunWorkerAsync( );
}

private void OnPollingWorker DoWork(object sender, DoWorkEventArgs args)
{
while(_pollingW orker.Cancellat ionPending == false &&
MSP430Programme r.TargetConnect ed() == false)
{
Thread.Sleep(50 0);
}

}
***** When I cancel (and it works cause this fires before
MSP430Programme r.TargetConnect ed() evaluates true
***** the Cancelled property of args is false.
private void OnPollingWorker Complete(object sender,
RunWorkerComple tedEventArgs args)
{
View.CloseViewW ithResult(Dialo gResult.OK);
}
public void CancelAndClose( )
{
_pollingWorker. CancelAsync();
}
</code>
Anyone see the problem? What am I missing? Is it a bug? I'm no threading
expert, in face I barely grasp the concepts, but from what I think I know
this isn't a race condition as MSP430Programme r.TargetConnect ed() is always
false.

Thanks for reading,
Steve
Jun 8 '06 #1
2 5400
When CancellationPen ding is true in your OnPollingWorker DoWork method
you need to set args.cancel = true
Steve wrote:
After running into a design wall with my traditional thread approach, I
realized that a BackgroundWorke r 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
CancellationPen ding in my DoWork handler) and WorkerComplete fires, the
value of Cancelled in the event args is always false.

Here is my code:
<code>

public void UpdateView()
{
if(MSP430Progra mmer.TargetConn ected())
{
View.CloseViewW ithResult(Dialo gResult.OK);
}

View.SetMessage Text(ProgramTar getResources.Ta rgetDisconnecte dMessage);

_pollingWorker = new BackgroundWorke r();
_pollingWorker. WorkerSupportsC ancellation = true;
_pollingWorker. DoWork += OnPollingWorker DoWork;
_pollingWorker. RunWorkerComple ted += OnPollingWorker Complete;
_pollingWorker. RunWorkerAsync( );
}

private void OnPollingWorker DoWork(object sender, DoWorkEventArgs args)
{
while(_pollingW orker.Cancellat ionPending == false &&
MSP430Programme r.TargetConnect ed() == false)
{
Thread.Sleep(50 0);
}

}
***** When I cancel (and it works cause this fires before
MSP430Programme r.TargetConnect ed() evaluates true
***** the Cancelled property of args is false.
private void OnPollingWorker Complete(object sender,
RunWorkerComple tedEventArgs args)
{
View.CloseViewW ithResult(Dialo gResult.OK);
}
public void CancelAndClose( )
{
_pollingWorker. CancelAsync();
}
</code>
Anyone see the problem? What am I missing? Is it a bug? I'm no threading
expert, in face I barely grasp the concepts, but from what I think I know
this isn't a race condition as MSP430Programme r.TargetConnect ed() is always
false.

Thanks for reading,
Steve


Jun 9 '06 #2
Thanks for clearing that up, I apprecaite it.
I guess I was thinking it would set that for me, but I suppose just cause I
request it to cancel doesn't mean it will, so you need to explicitly set it?
Hmm...

Thanks again,
Steve
<sd********@gma il.com> wrote in message
news:11******** **************@ h76g2000cwa.goo glegroups.com.. .
When CancellationPen ding is true in your OnPollingWorker DoWork method
you need to set args.cancel = true
Steve wrote:
After running into a design wall with my traditional thread approach, I
realized that a BackgroundWorke r 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
CancellationPen ding in my DoWork handler) and WorkerComplete fires, the
value of Cancelled in the event args is always false.

Here is my code:
<code>

public void UpdateView()
{
if(MSP430Progra mmer.TargetConn ected())
{
View.CloseViewW ithResult(Dialo gResult.OK);
}
View.SetMessage Text(ProgramTar getResources.Ta rgetDisconnecte dMessage);

_pollingWorker = new BackgroundWorke r();
_pollingWorker. WorkerSupportsC ancellation = true;
_pollingWorker. DoWork += OnPollingWorker DoWork;
_pollingWorker. RunWorkerComple ted += OnPollingWorker Complete;
_pollingWorker. RunWorkerAsync( );
}

private void OnPollingWorker DoWork(object sender, DoWorkEventArgs args)
{
while(_pollingW orker.Cancellat ionPending == false &&
MSP430Programme r.TargetConnect ed() == false)
{
Thread.Sleep(50 0);
}

}
***** When I cancel (and it works cause this fires before
MSP430Programme r.TargetConnect ed() evaluates true
***** the Cancelled property of args is false.
private void OnPollingWorker Complete(object sender,
RunWorkerComple tedEventArgs args)
{
View.CloseViewW ithResult(Dialo gResult.OK);
}
public void CancelAndClose( )
{
_pollingWorker. CancelAsync();
}
</code>
Anyone see the problem? What am I missing? Is it a bug? I'm no
threading
expert, in face I barely grasp the concepts, but from what I think I know
this isn't a race condition as MSP430Programme r.TargetConnect ed() is
always
false.

Thanks for reading,
Steve

Jun 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1819
by: jeffrod444 | last post by:
Hi, I've been having problems getting my forms to work correctly. If seen other threads addressing this issue, however, these are not working for me. The short of my problem is this. I am trying to open a new form and initialize it with a db query based on the info in the current form. This wasn't a problem until I changed the table's primary key to an Autonumber. tblLockCore.lockId is the autonumber at the source of the problem... ...
6
8997
by: Shyguy | last post by:
I have a form where one of the entries is "Contact". On BeforeUpdate I check the table for the existance of that Contact. A mesage box informs the user that the name is already in the table and cancels the event. What I want to do is clear the text from the text box to allow the user to enter another name without deleting it. I have tried to set focus, set value to "" etc. but nothing works. Any help is appreciated.
1
1700
by: JM | last post by:
i have an aspx page that imports 15k records from ms access into sql server. the page is running pretty slow, so i have to reevaulate the code. I tested the page, while is was processing, i hit the stop button in my browser, and even went to a different site. however the rowks keep getting inserted into the db. How can this be, i don't have the page loaded in my browser any more, i even loaded a different external website, but the rows...
2
8310
by: Edward | last post by:
For reporting purposes I use Crystal Reports. The user can select a printer from a dropdownlist. I set the printer with: PrintOptions.PrinterName = @"\\SERVERNAME\" + lstPrinter.SelectedValue.Trim(); and use PrintToPrinter(1, false, 0, 0); to print. Now I get the message: Error in File
3
1725
by: Chandra | last post by:
What happens to a cancelled http request from the server perspective? Here's the scenario. I request a page from the web server and page requires lot of processing. Before the response comes to the browser I either hit the Stop button on the browser or moved on to another page. Now at the server, does it continue to process the request? or does ASP.Net terminate the processing because the TCP connection of the HTTP requests is
14
1754
by: Ron L | last post by:
All I am working with a DataGrid and a form consisting of a number of text, checkbox, combobox controls, all bound to the same datatable. When I click on my "New" button, I create a new row, make it the current row, and allow the user to make changes in the form. If the user desires to cancel, they can click the "Cancel Changes" button. Here is where my problems start. Once the Cancel Changes button is clicked, the bindings on the...
1
4665
by: Mesan | last post by:
Has anyone else noticed that even though you handle an exception that happens within the background worker that the UnhandledException event still fires? For example, here's my ThreadException hookup and code : Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); void Application_ThreadException(object sender,
3
7088
by: perrog | last post by:
Hi! What is the expected behaviour when you send an XmlHttpRequest just before the page is about to unload? I'm sending a XmlHttpRequest on an onClick event, and I can inspect that the request is sent and responded in the network traffic, but my onReadyStateChange handler is notified with an error. It took me some time to deduce what the real problem was, and I think my browser begins to tear down the XmlHttpRequest when the page is
4
9669
by: Phil Stanton | last post by:
I am opening a report (in Preview) from a menu system I use the following code if there is no data in a report Private Sub Report_NoData(Cancel As Integer) MsgBox "There are no errors in Membership Head of Families", vbInformation Cancel = True
0
10465
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...
0
10242
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...
0
10021
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
9061
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
6800
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
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
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.