简体   繁体   中英

Getting different results using Debug.Writeline vs. RichTextBox.AppendText

I was wondering if anyone could explain why when I use the following code I get different results. For further explaination, I'm using a dll that was created in C#, it's an rcon framework. The richtextbox displays 3 lines then will not display anymore whereas my debug console continues to get data from my rcon connection.

I'm using:

Private Shared Sub HandleMessage(args As BattlEyeMessageEventArgs)
    Debug.WriteLine(args.Message)
    Form1.RichTextBox3.AppendText(args.Message & vbNewLine)
    Form1.RichTextBox3.SelectionStart = Form1.RichTextBox3.TextLength
    If args.Message = "Connected!" Then
        Form1.Button3.Enabled = True
    End If
End Sub

If it helps, here's the C# code for the EventHandler:

using System;

namespace BattleNET
{
    public delegate void BattlEyeMessageEventHandler(BattlEyeMessageEventArgs args);

    public class BattlEyeMessageEventArgs : EventArgs
{
    public BattlEyeMessageEventArgs(string message)
    {
        Message = message;
    }

    public string Message { get; private set; }
    }
}
private delegate void UpdateRichTextBox3Delegate(RichTextBox3 textBox, string text);
private void UpdateRichTextBox3(RichTextBox3 textBox, string text){
    if(textBox.InvokeRequired){
        textBox.Invoke(new UpdateRichTextBox3Delegate(UpdateRichTextBox3),new object[]{textBox, text});
        return;
    }
    textBox.AppendText(String.format("{0}{1}", text,Environment.NewLine));
}

Check if RichTextBox3 doesn't require to be invoked first before updating it.

call UpdateRichTextBox3(Form1.RichTextBox3, "some text to append");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM