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 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

Related Questions

I'm relatively new to .Net 4 and I am creating my FIRST WPF application
I am still relatively new at VB.Net and Visual Studio and I'm assuming that
I'm relatively new to .NET programming (and OOP in general) and I want to
Being relatively new to the .net game, I was wondering, has anyone had any
I'm relatively new to ASP.NET and was wondering if anyone could shed some light
I'm relatively new to web application programming so I hope this question isn't too
I'm relatively new to .NET GUI programming using WinForms (the project I'm working on
I am relatively new to .net. As I was trying to grasp the concept
I'm relatively new to .NET and have being using Linq2Sql for a almost a
I am relatively new to .NET programming and multithreading in general, and was wondering

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.