Background Worker - Monitor for 'CancelPending'?

jsurpless

Well-known member
Joined
Jul 29, 2008
Messages
144
Programming Experience
Beginner
Hi

As I understand it, I can issue a .Cancel command to a background worker task but all this action does it to set a flag - which I seemingly have to monitor for in my task...

What's the best way to monitor for .CancelPending?

Thanks!

-Justin
 
"the worker thread should periodically check CancellationPending and abort the background operation when it is set to true", you can do this between time consuming calls or during a loop that takes place in DoWork Event, the same places that is appropriate to report progress.
 
Hi John

If the following is what my 'DoWork' subroutine looks like

VB.NET:
 Private Sub BackgroundWorker_ProcessDrawings_DoWork(ByVal sender As System.Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker_ProcessDrawings.DoWork

        Try

            Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

            Call c_AutoCAD.Process_Drawings_Worker(worker, e)

  end sub

Could you elaborate on how I'd do this? I've used the .CancelAsync command and that apparently sets the .CancelPending flag... how do I abort the worker?

Thanks!
 
Since you only have a single call in DoWork you can't do anything about it there, you can do it in Process_Drawings_Worker method if you get a chance there.
 
Back
Top