A caution is also there on MSDN, check this also,
Caution:

Be aware that your code in the
DoWork<http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx>
event
handler may finish its work as a cancellation request is being made, and
your polling loop may miss
CancellationPending<http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.cancellationpending.aspx>
being
set to true. In this case, the
Cancelled<http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.cancelled.aspx>
flag
of 
System.ComponentModel.RunWorkerCompletedEventArgs<http://msdn.microsoft.com/en-us/library/system.componentmodel.runworkercompletedeventargs.aspx>
in
your 
RunWorkerCompleted<http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.runworkercompleted.aspx>
event
handler will not be set to true, even though a cancellation request was
made. This situation is called a race condition and is a common concern in
multithreaded programming. For more information about multithreading design
issues, see Managed Threading Best
Practices<http://msdn.microsoft.com/en-us/library/1c9txz50.aspx>
.

On Tue, Oct 13, 2009 at 12:20 PM, Benj Nunez <[email protected]> wrote:

>
> Hello everyone,
>
> I recently wrote a program that allows users to interrupt a process
> which runs within a thread.
> I have code that looks like this:
>
>        private void btnStop_Click(object sender, EventArgs e)
>        {
>            bwOverAll.CancelAsync();
>            btnStop.Enabled = false;
>        }
>
> I'm not sure if threads rely somewhat on what CPU the PC has. I have
> tested my program to run
> on the following PCs and I can start/stop threads at will with no
> issues:
>
>  PC#1) Windows XP Home with SP3. Intel Pentium D 2.80Ghz, 504mb ram,
> Hyperthreading enabled.
>  PC#2) Windows XP Pro with SP3, Intel Pentium 4, 2GB ram,
> Hyperthreading enabled.
>
>
> On the production machine however, I checked its specifications to be
> like this:
>
> PC#3) Windows XP Home, Intel Celeron.
>
>
> All three PCs have .net framework 3.5 installed.
>
> That's all I can remember. But I can check again about its ram and
> clock speed.
> Could you tell me exactly where to first look for in cases like this?
> Normally I expect that
> when I click the button to stop an action (threaded), there's a brief
> delay then the thread eventually stops. But in my case it didn't.
>
>
> Any advice?
>
>
>
>
> Benj
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Reply via email to