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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:13:08+00:00 2026-06-13T12:13:08+00:00

I want to run an own class in another thread, but if I do

  • 0

I want to run an own class in another thread, but if I do that I can’t use my, for example, labels inside of an EventHandler, how can I avoid that?

That’s how my code looks:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ts3_Movearound
{
    public partial class Form1 : Form
    {
        TS3_Connector conn = new TS3_Connector();
        Thread workerThread = null;
        public Form1()
        {
            InitializeComponent();
            conn.runningHandle += new EventHandler(started);
            conn.stoppedHandle += new EventHandler(stopped);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //System.Threading.Thread connw = new System.Threading.Thread(conn);
            workerThread = new Thread(conn.Main);
            workerThread.Start();
        }

        public void started(Object sender, EventArgs e)
        {
            label1.Text = "Status: Running!";
        }
        public void stopped(Object sender, EventArgs e)
        {
            label1.Text = "Status: Stopped!";
        }
    }
}

And that’s the error:

InvalidOperationExpetion in Line “label1.Text = “Status: Running!”;”

  • 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-13T12:13:09+00:00Added an answer on June 13, 2026 at 12:13 pm

    You can only update the control via the UI thread. Use label1.Invoke() to do that:

    label1.Invoke((MethodInvoker)delegate {
        label1.Text = "Status: Running!";"
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the sample code that I used to run another application inside a
I'm implimenting my own ApplicationContext class that uses the singleton pattern. I want to
Want to run javascript function from parent window in child window Example I have
I can run normally SQLAlchemy when everything is in one file. I now want
I know that CAS is of limited value , but I want to learn
We have tests using WatiN that we want to run on our CruiseControl.NET server.
I want to have a number of objects that can be added to a
Is there a feasible way to get my own code run whenever any class
I want run all script from the directory . Like , The directory contains
I want run a script as follows: runner: ssh 'java program &' ssh 'java

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.