[Mono-bugs] [Bug 373153] New: Incorrect behavior of BackgroundWorker.CancelAsync()

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 23 02:34:59 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=373153


           Summary: Incorrect behavior of BackgroundWorker.CancelAsync()
           Product: Mono: Class Libraries
           Version: SVN
          Platform: i386
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: MonkeeSage at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Created an attachment (id=203495)
 --> (https://bugzilla.novell.com/attachment.cgi?id=203495)
test case

According to MSDN, System.ComponentModel.BackgroundWorker.CancelAsync() is
supposed to set the CancellationPending property to true, to be accessed from
the worker thread--nothing more.

From
http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.cancelasync.aspx
  CancelAsync submits a request to terminate the pending background operation
and
  sets the CancellationPending property to true.

  When you call CancelAsync, your worker method has an opportunity to stop its
  execution and exit. The worker code should periodically check the
  CancellationPending property to see if it has been set to true.

From
http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.cancellationpending.aspx
  If CancellationPending is true, then the CancelAsync method has been called
on
  the BackgroundWorker.

  This property is meant for use by the worker thread, which should
periodically
  check CancellationPending and abort the background operation when it is set
to
  true.

See also the sample code at
http://msdn2.microsoft.com/en-us/library/hybbz6ke.aspx

However, in current SVN (and in mono 1.2.6, and presumably all versions in
between and before, though I haven't looked), CancelAsync() sets cancel_pending
to true, then calls AsyncOperation.PostOperationCompleted(), with a delegate
that is Post()'ed to the SynchronizationContext and eventually calls the
RunWorkerCompleted event handler from OnRunWorkerCompleted; after this,
cancel_pending is set to false and CancelAsync() returns.

This means that CancellationPending is only true in the RunWorkerCompleted
callback, and further, the RunWorkerCompleted callback is executed while the
worker thread is still working(!)...this seems very wrong.

On MSFT, the test case works as expected; when BackgroundWorker.CancelAsync()
is called, it sets CancellationPending to true and when the OnDoWork handler
sees this, it exits. However, on Mono, OnDoWork never sees the property as
true, and the OnWorkDone handler runs even though OnDoWork is still executing.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list