TextBox loses text when InvokeRequired == false
- by Tom
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);
}