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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:21:59+00:00 2026-06-04T18:21:59+00:00

I have several process that need to run in the background of a Windows

  • 0

I have several process that need to run in the background of a Windows Forms application, because they take too much time and I do not want to freeze the user interface until they completely finish, I would like to have an indicator to show the process of each operation, so far I have a form to show the progress of each operation but my operations run synchronously.

So my question is what is the easiest way to run these operation (that access the database) async??

I forgot one important feature that the application requires, the user will have the option to cancel any operation at any time. I think this requirement complicates the application a lot, at least with my current skills, so basically I would like to enphatize that I need a solution easy to understand, and easy to implement. i am aware there will be good practices to follow but at this point I would like some code working later I with more time I would refactor the code

  • 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-04T18:22:00+00:00Added an answer on June 4, 2026 at 6:22 pm

    Well in C# there are several ways to accomplish this

    Personally I would recommend you to try the Reactive Extensions

    http://msdn.microsoft.com/en-us/data/gg577609.aspx

    You can actually do something like this:

    https://stackoverflow.com/a/10804404/1268570

    I created this for you, this is really easy although it is not thread-safe but this would be a good start point

    In a form

    var a = Observable.Start(() => Thread.Sleep(8000)).StartAsync(CancellationToken.None);
    var b = Observable.Start(() => Thread.Sleep(15000)).StartAsync(CancellationToken.None);
    var c = Observable.Start(() => Thread.Sleep(3000)).StartAsync(CancellationToken.None);
    
    Manager.Add("a", a.ObserveOn(this).Subscribe(x => MessageBox.Show("a done")));
    Manager.Add("b", b.ObserveOn(this).Subscribe(x => MessageBox.Show("b done")));
    Manager.Add("c", c.ObserveOn(this).Subscribe(x => MessageBox.Show("c done")));
    
    private void button1_Click(object sender, EventArgs e)
    {
        Manager.Cancel("b");
    }
    

    Manager utility

    public static class Manager
    {
        private static IDictionary<string, IDisposable> runningOperations;
    
        static Manager()
        {
            runningOperations = new Dictionary<string, IDisposable>();
        }
    
        public static void Add(string key, IDisposable runningOperation)
        {
            if (runningOperations.ContainsKey(key))
            {
                throw new ArgumentOutOfRangeException("key");
            }
    
            runningOperations.Add(key, runningOperation);
        }
    
        public static void Cancel(string key)
        {
            IDisposable value = null;
            if (runningOperations.TryGetValue(key, out value))
            {
                value.Dispose();
                runningOperations.Remove(key);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a Scala (2.9.1-1) application that needs to process several million rows
I have a view that can take several seconds to process a GET request
I have a .Net application that needs to run several executables. I'm using the
We have a scripting engine (running under Windows) that launches another application several thousand
In my iOS app I have several UIElement s that can process user input:
I'm modeling an algorithm in Spin. I have a process that has several channels
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
I have a script, that I need to run after committing to a project
I need to (on user demand) run an admin process several times from my
I am in the process of writing an application that communicates with several devices

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.