Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground Worker thread not ending on cancellation
    primarykey
    data
    text
    <p>I am having a little issue, I finally figured out how to add a background worker to my application now my only problem is it does not end the thread, or atleast not fast enough when I am clicking my cancel button. I must be doing something wrong. I would like for it to abort the thread as soon as the button is clicked. Is this feasable? My thread is by no means extensive. </p> <p>I am going to post some examples of the way I am doing it.</p> <pre><code> Public Sub New() InitializeComponent() bw.WorkerReportsProgress = True bw.WorkerSupportsCancellation = True AddHandler bw.DoWork, AddressOf bw_DoWork ' AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted End Sub </code></pre> <p>My DoWork Event</p> <pre><code> Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) If bw.CancellationPending = True Then e.Cancel = True WorkEventRunning = False Else CheckForIllegalCrossThreadCalls = False Dim worker As BackgroundWorker = CType(sender, BackgroundWorker) 'my long winded event ' more of my long winded event. End if </code></pre> <p>My Cancel button Code</p> <pre><code> Private Sub ToolStripButton2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click 'Stop If bw.WorkerSupportsCancellation = True Then WorkEventRunning = False bw.CancelAsync() bw.Dispose() End If </code></pre> <p>And my WorkCompleted</p> <pre><code> Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) If e.Cancelled = True Then 'canceled WorkEventRunning = False ElseIf e.Error IsNot Nothing Then MsgBox(e.Error.Message) Else 'done End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload