Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:57:13+00:00 2026-06-10T14:57:13+00:00

I am having a little issue, I finally figured out how to add a

  • 0

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.

I am going to post some examples of the way I am doing it.

    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

My DoWork Event

    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

My Cancel button 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

And my WorkCompleted

     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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:57:15+00:00Added an answer on June 10, 2026 at 2:57 pm

    In the DoWork event, test for CancellationPending inside the long winded event.
    Supposing that this long procedure contains a For-Loop or a ForEach then at every loop test for CancellationPending

    For example:

    Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
    Dim x as Integer
    For x = 0 to 1000000
        If worker.CancellationPending = True Then 
            e.Cancel = True 
            Return 
        Else 
           .... ' Execute the works for this loop
        End If
    Next
    

    The same test could be done inside the RunWorkerCompleted event because CancelAsync() sets the internal value for the CancellationPending property. See this question to look at the inner workings of CancelAsync()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just having a little issue figuring this jquery problem out. I have a table
Im wondering if someone could help me out with a little issue im having.
I'm having a little issue...I setup a rails application that is to serve a
I'm having a little issue with an application I'm making. I have a page
I've only just recent began learning C++ and am having a little issue with
I'm having a little issue right now that has turned into a festering wound.
im having a little issue here. I have MediaElement.js set on my project. It
i'm having a little issue with doctrine using symfony 1.4 (I think it's using
I was hoping someone could help me with a little issue I'm having trouble
I'm having a little trouble getting my head around a Javascript animated scroll issue.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.