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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:44:00+00:00 2026-05-26T20:44:00+00:00

my winform has a thread running and I need it to notify main thread

  • 0

my winform has a thread running and I need it to notify main thread once it’s done, then the main thread can set progressbar back to normal state.

currently, what i have is something as following

------begin---------
// codes before....
call thread one....
create thread two instance then start thread two
---------end------------------

in thread two, i have

--------begin------
 while(threadOne.isalive){
   Thread.Sleep(500);
 }
 call setProgressbar delegate
 ---------end----------------

i did this instead of put an var in thread one is because thread one is recursive method….
i wonder if this correct way of doing it, can someone help?
thanks

  • 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-26T20:44:00+00:00Added an answer on May 26, 2026 at 8:44 pm

    EDIT: The answer below the line answers your explicit question, but if you’re using .NET 4, you should consider thinking at a higher level of abstraction instead – tasks. The Task Parallel Library exposes a richer set of functionality than “bare” threads, and you can do things like registering continuations (with Task.ContinueWith) – and there you can even specify which task scheduler to use, so you can directly specify that when a background task has finished, a particular action should be invoked on the UI thread.


    Original answer

    The simplest way would be to delegate the first thread’s responsibility, e.g.

    public void WrappedStart()
    {
        bool success = false;
        try
        {
            StartWork();
            success = true;
        }
        finally
        {
            NotifyCompleted(success);
        }
    }
    
    private void StartWork()
    {
        // Do your real work here
    }
    
    ...
    
    Thread t = new Thread(WrappedStart);
    t.Start();
    

    If your thread might do different things, you could change your WrapperStart to take the action to wrap:

    public void WrappedStart(Action action)
    {
        ...
    }
    

    Then:

    Thread t = new Thread(() => WrappedStart(RealWork));
    t.Start();
    

    Note that if you do want the multi-thread solution, just use Thread.Join instead of looping explicitly.

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

Sidebar

Related Questions

Does anyone know how I can resize a winform when it has no border.
My company has an existing established WinForm application which in running on WinXP. The
I have a Winform app that has a backgroundWorker thread and does all operations
I have a singleton that has a running thread for obtaining records from a
I have a winform app that has tabcontrols that are 3 layers deep. I
I've got a WinForm where the user has the ability to drag an item
I've got a winform with a BindingSource that has an int property named Opacity
I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to
I want to run an operation on a background thread. When it has completed
I have a C# winform application. it has many forms with different functionalities. These

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.