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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:50:23+00:00 2026-05-22T00:50:23+00:00

I have a BackgroundWorker thread that is posting messages, using BeginInvoke on a textbox

  • 0

I have a BackgroundWorker thread that is posting messages, using BeginInvoke on a textbox in the GUI. The method, write_debug_text, that displays text in the textbox uses AppendText and also writes the text to the Console.

The appearance is that the BackgroundWorker is writing too fast for the write_debug_text to keep up. I set a breakpoint at write_debug_text and have to wait a long time before it is hit. Many calls to ‘BeginInvoke` occur before the breakpoint is hit.

I’m looking for a real-time display of messages on the UI, much like the System.Console in the VS C# Express IDE.

From searching on SO, I understand that AppendText is the faster method to use and that strings may have to be reallocated.

Some replies suggest using StringBuilder then periodically writing that text to the textbox. But this requires adding more events and timers; which I would rather not do (my simple application keeps getting more and more complex).

How can I either write real-time to the Textbox (and have it display)?

My current idea is to create a widget inheriting from Textbox that uses a text queue and timer.

Edit 1: Sample code

Here is a fragment of my code:

    private m_textbox;
    //...
    m_textbox.BeginInvoke(new write_debug_text_callback(this.write_debug_text),
                                      new object[] { debug_text });
    return;

private void write_debug_text(string text)
{
    string time_stamp_text = "";
    time_stamp_text = DateTime.Now.ToString() + "   ";
    time_stamp_text += text;
    m_textbox.AppendText(time_stamp_text);
    m_textbox.Update();
    System.Console.Write(time_stamp_text);
    return;
}

I have tried changing BeginInvoke to Invoke and my application is hung. When I pause / break using the debugger, the execution pointer is on the call to Invoke.

BTW, I’ve got many years experience with Java, C++, and C. I am on my 5th month with C#.

  • 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-22T00:50:24+00:00Added an answer on May 22, 2026 at 12:50 am

    I used @Jeffre L. Whitledge’s advice and reduce the number of string allocations. Since this is a closed application with a fixed number of strings, I cached the strings. This produced a side-effect of my program executing significantly faster.

    One of my issues is still the slowness in Windows responding to messages. This can be seen when the progress bar is updated. There is a definite delay from when a message is sent (such as append text), and when it is performed.

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

Sidebar

Related Questions

I'm using a BackgroundWorker to trigger a thread, in turn calling a function, which
I have a BackgroundWorker that I use on a Search. Two different Searches can
I have a function that loops through my list of objects, makes some checks
In my program, there will be a time where I have to call Thread.Sleep(Timeout.Infinite);
I have a closed-source API for some hardware sensor that I use to query
I have a WPF application, where I make a long-running WCF call using the
I have a WPF application that executes external programs to process media files, and
I have a winforms app, and I need to access the Handle property of
I have seen this problem before but I haven't seen an answer to the
DataTable dt = new DataTable(); dt.Columns.Add(col1); dt.Columns.Add(col2); dt.Columns.Add(col3); dt.Columns.Add(col4); dt.Columns.Add(col5); dataGridView1.DataSource = dt; dataGridView1.Columns.RemoveAt(3);

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.