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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:09:40+00:00 2026-05-11T03:09:40+00:00

I cannot figure out how to make a C# Windows Form application write to

  • 0

I cannot figure out how to make a C# Windows Form application write to a textbox from a thread. For example in the Program.cs we have the standard main() that draws the form:

static void Main() {     Application.EnableVisualStyles();     Application.SetCompatibleTextRenderingDefault(false);     Application.Run(new Form1()); } 

Then we have in the Form1.cs:

public Form1() {     InitializeComponent();      new Thread(SampleFunction).Start(); }  public static void SampleFunction() {     while(true)         WindowsFormsApplication1.Form1.ActiveForm.Text += 'hi. '; } 

Am I going about this completely wrong?

UPDATE

Here is the working code sample provided from bendewey:

public partial class Form1 : Form {     public Form1()     {         InitializeComponent();         new Thread(SampleFunction).Start();     }      public void AppendTextBox(string value)     {         if (InvokeRequired)         {             this.Invoke(new Action<string>(AppendTextBox), new object[] {value});             return;         }         textBox1.Text += value;     }      void SampleFunction()     {         // Gets executed on a seperate thread and          // doesn't block the UI while sleeping         for(int i = 0; i<5; i++)         {             AppendTextBox('hi.  ');             Thread.Sleep(1000);         }     } } 
  • 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. 2026-05-11T03:09:41+00:00Added an answer on May 11, 2026 at 3:09 am

    On your MainForm make a function to set the textbox the checks the InvokeRequired

    public void AppendTextBox(string value) {     if (InvokeRequired)     {         this.Invoke(new Action<string>(AppendTextBox), new object[] {value});         return;     }     ActiveForm.Text += value; } 

    although in your static method you can’t just call.

    WindowsFormsApplication1.Form1.AppendTextBox('hi. '); 

    you have to have a static reference to the Form1 somewhere, but this isn’t really recommended or necessary, can you just make your SampleFunction not static if so then you can just call

    AppendTextBox('hi. '); 

    It will append on a differnt thread and get marshalled to the UI using the Invoke call if required.

    Full Sample

    public partial class Form1 : Form {     public Form1()     {         InitializeComponent();         new Thread(SampleFunction).Start();     }      public void AppendTextBox(string value)     {         if (InvokeRequired)         {             this.Invoke(new Action<string>(AppendTextBox), new object[] {value});             return;         }         textBox1.Text += value;     }      void SampleFunction()     {         // Gets executed on a seperate thread and          // doesn't block the UI while sleeping         for(int i = 0; i<5; i++)         {             AppendTextBox('hi.  ');             Thread.Sleep(1000);         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 131k
  • 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 Don't do it. It's 5 years deprecated, and it was… May 12, 2026 at 6:21 am
  • Editorial Team
    Editorial Team added an answer If you don't want to go for additional tools, try… May 12, 2026 at 6:21 am
  • Editorial Team
    Editorial Team added an answer Have you tried: PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream); // Build… May 12, 2026 at 6:21 am

Related Questions

So I'm trying to make a client for my server in C#, that accepts
I've deconstructed a standard WPF button using Blend and have managed to create a
I have the following makefile that I use to build a program (a kernel,
In my Android program, I have some code that downloads a file. This works

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.