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

  • Home
  • SEARCH
  • 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 147259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:45:00+00:00 2026-05-11T08:45:00+00:00

I am relatively new to C#/.Net. I’m developing a desktop application that requires multi

  • 0

I am relatively new to C#/.Net. I’m developing a desktop application that requires multi threading. I came up with the following pattern below as a base. I was wondering if anyone could point out how to make it better in terms of coding, being thread safe, and being efficient.

Hopefully this makes some sense.


public abstract class ThreadManagerBase {     // static class variables      private static ThreadManagerBase instance = null;     private static BackgroundWorker thread = null;     private static ProgressBarUIForm progress = null;      /// <summary>     /// Create a new instance of this class. The internals are left to the derived class to figure out.     /// Only one instance of this can run at any time. There should only be the main thread and this thread.     /// </summary>     public abstract static ThreadManagerBase NewInstance();      /// <summary>     /// Clears the instance.     /// </summary>     public static void ClearInstance()     {         instance = null;     }      /// <summary>     /// Initializes the background worker with some presets.     /// Displays progress bar.     /// </summary>     private abstract static void InitializeThread()     {         thread = new BackgroundWorker();          thread.WorkerReportsProgress = true;         thread.WorkerSupportsCancellation = true;          thread.DoWork += new DoWorkEventHandler(thread_DoWork);         thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(thread_RunWorkerCompleted);         thread.ProgressChanged += new ProgressChangedEventHandler(thread_ProgressChanged);          thread.RunWorkerAsync();          progress = new ProgressBarUIForm();          progress.EnableCancelButton = true;          progress.UserCanceled += new EventHandlerCancelClicked(progress_UserCanceled);          progress.ShowDialog();          thread.Dispose();          thread = null;     }      private static void progress_UserCanceled(bool userCanceled)     {         thread.CancelAsync();     }      private static void thread_ProgressChanged(object sender, ProgressChangedEventArgs e)     {         progress.SetProgressLevel = e.ProgressPercentage;         progress.SetProgressMessage = e.UserState.ToString();     }      private static void thread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)     {         progress.Close();          progress = null;     }      private static void thread_DoWork(object sender, DoWorkEventArgs e)     {         ProcessWork();     }      private abstract static void ProcessWork()     {         // do actuall stuff here.         // the derived classes will take care of the plumbing.     } } 
  • 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. 2026-05-11T08:45:01+00:00Added an answer on May 11, 2026 at 8:45 am

    You don’t need a BackgroundWorker unless you want to be spoonfed, normal threads are perfectly acceptable, as long as you follow the rules.

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

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For frequent uploads of small files, the fastest way would… May 11, 2026 at 4:01 pm
  • Editorial Team
    Editorial Team added an answer Symbolic equation solving is a complex problem and there is… May 11, 2026 at 4:01 pm
  • Editorial Team
    Editorial Team added an answer Have you tried having the ID be TEST.html? My guess… May 11, 2026 at 4:01 pm

Related Questions

I am relatively new to C#/.Net. I'm developing a desktop application that requires multi
What experience have you had with introducing a Ribbon style control to legacy MFC
I am relatively new to C# and each time I begin to work on
I have a DataGrid that I use to display an inbox of information. I
I need to create a photo gallery for a website running IIS 4.0 or

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.