简体   繁体   English

使用Debug.Writeline与RichTextBox.AppendText获得不同的结果

[英]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. 为了进一步说明,我使用的是在C#中创建的dll,它是一个rcon框架。 The richtextbox displays 3 lines then will not display anymore whereas my debug console continues to get data from my rcon connection. richtextbox显示3行,然后将不再显示,而我的调试控制台继续从rcon连接获取数据。

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: 如果有帮助,这里是EventHandler的C#代码:

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. 检查RichTextBox3是否不需要在更新之前先被调用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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