0

我想知道是否有人可以解释为什么当我使用以下代码时会得到不同的结果。为了进一步解释,我使用的是在 C# 中创建的 dll,它是一个 rcon 框架。Richtextbox 显示 3 行,然后将不再显示,而我的调试控制台继续从我的 rcon 连接获取数据。

我正在使用:

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

如果有帮助,这里是 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; }
    }
}
4

1 回答 1

0
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));
}

检查 RichTextBox3 是否不需要在更新之前先被调用。

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

于 2012-08-09T22:04:39.933 回答