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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:00:57+00:00 2026-05-17T02:00:57+00:00

I have a windows forms program with a form MainForm. On a button press

  • 0

I have a windows forms program with a form MainForm. On a button press I start a code that runs (pulses) on every 0.5secs on another thread. I want to modify many things, like labels, progressbars on my MainForm, from the Pulse method. How is this possible?
So I would like to know, how to interract with variables, values, in that thread, and the MainForm. Modify each other, etc..

On foo button click, I tell my pulsator to start.
Pulsator.Initialize();

Here is the Pulsator class:

public static class Pulsator
{
    private static Thread _worker;

    public static void Initialize()
    {
        _worker = new Thread(Pulse);
        _worker.IsBackground = true;
        _worker.Start();
    }

    public static void Close()
    {
        if (_worker != null)
        {
            _worker.Abort();
            while (_worker.IsAlive || _worker.ThreadState != ThreadState.Stopped)
            {
               //closing
            }
        }
    }

    public static void Pulse()
    {
        if (_worker != null)
        {
            while (true)
            {
                SomeOtherClass.Pulse();
                Thread.Sleep(500);
            }
        }
        else
        {
            SomeOtherClass.Pulse(); // yeah I know this doesnt needed
        }
    }
}

SomeOtherClass Pulse method looks like :

    public static void Pulse()
    {
        //here I will have several values, variables, and I want to show results,
        // values on my MainForm, like:
        Random random = new Random();
        MainForm.label1.Text = random.Next(123,321).ToString(); // I hope you know what I mean
    }

Of course it’s much complicated, it’s just a silly example.

  • 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-17T02:00:57+00:00Added an answer on May 17, 2026 at 2:00 am

    As others already mentioned, you have to use Control.Invoke to change the UI controls from the background thread.

    Another option is to use System.ComponentModel.BackgroundWorker (it’s available in the form designer toolbox). You could then take a regular forms timer, to call the RunWorkerAsync-Method and do your background work in the DoWork event handler, which is automatically called from another thread.

    From there, you can hand data back to the main thread, by calling ReportProgress. This will raise the ProgressChanged event in the main thread, where you are free to update all your UI controls.

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

Sidebar

Related Questions

I have a form with label that is updating by System.Windows.Forms.Timer control every 2
Creating a Windows Forms Application in C#, I have a program that I am
I have a program which displays an image to the windows form, and places
I'm having problem when running my Windows Forms program. In the program, I have
I have created a program with Windows Forms in C# and the architecture is
I have Windows Forms UI, that allows me to enter format for string formatting
I have a windows forms client that consumes an ASP.net web service. It's my
I have a windows forms application in .NET 3.5. There's one form with 20
I have a Windows Forms project in Visual Studio that reads configuration files from
I have a .net windows forms application that needs to open directly to the

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.