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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:28:22+00:00 2026-05-11T17:28:22+00:00

I have some unsolved issue with threads. It’s my first time doing it. I

  • 0

I have some unsolved issue with threads. It’s my first time doing it. I know how to use one thread to write in a textBox, but I have no idea how to use two of them to do the job. Anyone have a clue what do I have to do to be able to use two threads to write to the same textBox, but not in the same time. Thank you.

  • 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-11T17:28:22+00:00Added an answer on May 11, 2026 at 5:28 pm

    Here’s an example that uses two threads to write random numbers to a multi-line text box. As Brandon and Jon B noted, you need to use Invoke() to serialize the calls to the GUI thread.

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        Random m_random = new Random((int)DateTime.Now.Ticks);
        ManualResetEvent m_stopThreadsEvent = new ManualResetEvent(false);
    
        private void buttonStart_Click(object sender, EventArgs e)
        {
            Thread t1 = new Thread(new ThreadStart(ThreadOne));
            Thread t2 = new Thread(new ThreadStart(ThreadTwo));
    
            t1.Start();
            t2.Start();
        }
    
        private void ThreadOne()
        {
            for(;;)
            {
                int n = m_random.Next(1000);
                AppendText(String.Format("One: {0}\r\n", n));
                if(m_stopThreadsEvent.WaitOne(n))
                {
                    break;
                }
            }
        }
    
        private void ThreadTwo()
        {
            for(;;)
            {
                int n = m_random.Next(1000);
                AppendText(String.Format("Two: {0}\r\n", n));
                if(m_stopThreadsEvent.WaitOne(n))
                {
                    break;
                }
            }
        }
    
        delegate void AppendTextDelegate(string text);
    
        private void AppendText(string text)
        {
            if(textBoxLog.InvokeRequired)
            {
                textBoxLog.Invoke(new AppendTextDelegate(this.AppendText), new object[] { text });
            }
            else
            {
                textBoxLog.Text = textBoxLog.Text += text;
            }
        }
    
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_stopThreadsEvent.Set();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 132k
  • Answers 132k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer for Objective-C the best is Xcode - if you have… May 12, 2026 at 6:22 am
  • Editorial Team
    Editorial Team added an answer The MS Chart Controls are pretty good and free, but… May 12, 2026 at 6:22 am
  • Editorial Team
    Editorial Team added an answer For a general understanding of linkers, read the book “Linkers… May 12, 2026 at 6:22 am

Related Questions

I have some unsolved issue with threads. It's my first time doing it. I
I have the weirdest of problems. I have a jQuery function that animates the
I am currently porting a project with a few hundred code files and dependencies
In trying to figure out this problem (which is still unsolved and I still
I have some UI in VB 2005 that looks great in XP Style, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.