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 2 5401
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
...
|
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.
|
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...
|
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
|
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
| |
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...
|
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,
|
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
|
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
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |