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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:13:46+00:00 2026-05-28T04:13:46+00:00

Possible Duplicate: How to update GUI from another thread in C#? I have form

  • 0

Possible Duplicate:
How to update GUI from another thread in C#?

I have form with textBox1 and textBox2. I need very simple example of an extra thread to fill textBox2, just to understand principle. So far i am using MessageBox to display value, but i want to use textBox2 instead. Here is my code:

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

namespace Threads_example
{
    public partial class Form1 : Form
    {
        Thread t = new Thread(t1);
        internal static int x1 = 1;


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        static void t1()
        {
            do
            {
                x1++;
                MessageBox.Show("x1 - " + x1.ToString());
            }
            while(x1<10);
        }


        private void button1_Click(object sender, EventArgs e)
        {

            t.Start();

            for (int x = 1; x < 100000; x++)
            {
                textBox1.Text = x.ToString();
                textBox1.Refresh();
            }
        }

    }
}
  • 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-28T04:13:47+00:00Added an answer on May 28, 2026 at 4:13 am

    You need to invoke UI actions in the GUI thread.
    It can be done with something like this:

    private void RunFromAnotherThreadOrNot()
    {
               if (InvokeRequired)
               {
                   Invoke(new ThreadStart(RunFromAnotherThread));
                   return;
               }
    
    
               textBox2.Text = "What Ever";
               // Other UI actions
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to update GUI from another thread in C#? I've currently got
Possible Duplicate: How to update GUI from another thread in C#? My Timer event
Possible Duplicate: How to update GUI from another thread in C#? Following scenario: I
Possible Duplicate: update one table with data from another Extreme SQL noob here. I
Possible Duplicate: Java GUI repaint() problem? I write a Java code, but I have
Possible Duplicate: Cross-thread operation not valid: Control accessed from a thread other than the
Possible Duplicate: Update label location in C#? I am creating a custom windows form
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: Update app engine entity I need to update entity that I loaded
Possible Duplicate: More efficient way of updating UI from Service than intents? I have

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.