TextBox loses text when InvokeRequired == false

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-05-20T06:14:34Z Indexed on 2010/05/20 6:20 UTC
Read the original article Hit count: 214

Filed under:

This is modified code I found on this site.

When appending text to a TextBox and InvoveRequired is false the text will display in the box but the next time the function is called and InvokeRequired is true the text string placed by the first call is lost (""). Multiple calls when InvokeRequired is true work as expected.

comBox is a type TextBox with multline = true.

Any help would be appreciated.

 public void LogComText(string comText, bool newline)
    {
        if (comBox.InvokeRequired)
        {

            comBox.BeginInvoke(new Action(delegate
            {
                LogComText(comText, newline);
            }));
            return;
        }
        comBox.AppendText(comText);
        if (newline) comBox.AppendText(Environment.NewLine);


    }

© Stack Overflow or respective owner

Related posts about c#