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 6052873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:58:37+00:00 2026-05-23T07:58:37+00:00

I have a BackgroundWorker DoWork function as follows private void WorkerGetFeedData(object sender, DoWorkEventArgs args)

  • 0

I have a BackgroundWorker DoWork function as follows

    private void WorkerGetFeedData(object sender, DoWorkEventArgs args)
    {
            _feed.FetchUserData(_userNameCollection);
    }

The FetchUserData is a function in another class(whose object is _feed) in another project in the same solution. The data fetch process takes considerable time and I’d like for the user to be able to cancel the process if necessary. How do I convey a cancel operation from the user to a function call elsewhere and just stop it?

  • 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-05-23T07:58:37+00:00Added an answer on May 23, 2026 at 7:58 am

    You can use BackgroundWorker.CancelAsync method. Here’s more info with example: MSDN

    To be more exact to your problem, pass the worker to FetchUserData. It is the sender parameter. Then in the FetchUserData function you can check if the flag BackgroundWorker.CancellationPending is set and finish your method.

    void FetchUserData(IEnumerable<Users> userNameCollection, BackgroundWorker worker)
    {
        // ...
    
        if(worker.CancellationPending)
        {
            // Finish method..
        }
    }
    

    And the WorkerGetFeedData method:

    private void WorkerGetFeedData(object sender, DoWorkEventArgs args)
    {
            var worker = sender as BackgroundWorker;
            if(worker != null)
                _feed.FetchUserData(_userNameCollection, worker);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small WinForms app that utilizes a BackgroundWorker object to perform a
In my DoWork() function I register with our sip server. Then I have to
I have just stumbled across the Backgroundworker object, and it seems like the tool
I have some problem with backgroundWorker class. I wish I could within one function
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to
I have a longer running multi-step process using BackgroundWorker and C#. I need to
I have some code which is been running by a backgroundworker I'd like some
I have a long running series of operations in a .NET 2.0 BackgroundWorker thread.
I have a WPF ListView that I am trying to filter within a BackgroundWorker.

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.