Vb.net ListView未从OutputDataReceived事件(System.Diagnostics.Process)添加字符串

Vb.net ListView未从OutputDataReceived事件(System.Diagnostics.Process)添加字符串,vb.net,listview,Vb.net,Listview,我有一个程序,它启动一个javajar文件并在运行时获取输出;来自PowerBot.org的RSBot 一切正常,但我的ListView没有添加OutputDataReceived事件中的文本,但我可以在MessageBox中显示它;或Debug.WriteLine 我的ListView被添加到一个主题类中,但唯一修改的东西不是所有者绘制的 Class GhostListView Inherits ListView Sub New() Me.BackColor = Col

我有一个程序,它启动一个javajar文件并在运行时获取输出;来自PowerBot.org的RSBot 一切正常,但我的ListView没有添加OutputDataReceived事件中的文本,但我可以在MessageBox中显示它;或Debug.WriteLine

我的ListView被添加到一个主题类中,但唯一修改的东西不是所有者绘制的

Class GhostListView
Inherits ListView
    Sub New()
        Me.BackColor = Color.FromArgb(255, 21, 21, 21)
        Me.BorderStyle = BorderStyle.FixedSingle
        Me.ForeColor = Color.GhostWhite

        Me.View = Windows.Forms.View.Details
        Me.FullRowSelect = True
    End Sub
End Class
因此,没有任何修改会阻止以下内容添加到我的ListView中

Shared Sub RSBotProc_Output(sender As Object, e As DataReceivedEventArgs) Handles RSBotProcess.OutputDataReceived
    'Sub is shared because the Process is declared publicly as shared
    'Public Shared WithEvents RSBotProcess as Process = Nothing
    Functions.AddBotOutput(e)
    Functions.Log("Output Svc", "Received Output from Bot: " & e.Data)
    Debug.WriteLine("Recvd: " & e.Data)
End Sub
函数类,如上所述

调试中的输出

但是,我的ListView为空,项目计数为0。。。 我在这里有点迷路了,我有一种感觉,问题就在眼前,但我已经试着把这个bug压扁了大约20分钟,我可能只是略过了这个问题。。。我似乎时不时地这样做,但这次即使是橡皮鸭调试也帮不了我。 此外,如果需要,我可以上传整个项目,如果有人愿意,我可以让他们看一看

编辑

为了确保从Functions类调用我的log/addtobot,我添加了一个调试,输出发送到函数的内容 该项目的产出:

Functions#AddBotOutput() - Attempting to add '[INFO] Optimising your experience'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Optimising your experience'
Recvd: [INFO] Optimising your experience
Functions#AddBotOutput() - Attempting to add '[INFO] Starting bot'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Starting bot'
Recvd: [INFO] Starting bot
Functions#AddBotOutput() - Attempting to add '[INFO] Loading game'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Loading game'
Recvd: [INFO] Loading game

你掉进了一个标准的VB.NET陷阱。使用类型名而不是对象引用(如frmBotOutput)是一个令人讨厌的面向对象编程黑洞。当你在另一根线上使用它时,它会在你脸上爆炸。您的RSBotProc_输出未在UI线程上运行。除了学习正确的OOP技术和线程安全编程,还需要一年的时间,最快的修复方法是分配RSBotProcess.SynchronizingObject属性。感谢您回复我的解释和可能的修复方法,Hans,这就是我想要的哈哈。我将研究SynchronizingObject,如果它不起作用,我将研究另一种捕获流程输出的方法,但是出于某种原因,这似乎是最有效的方法。
Recvd: [INFO] Optimising your experience
Recvd: [INFO] Starting bot
Recvd: [INFO] Loading game
Recvd: [INFO] Unpacking client (7dea8f)
Recvd: [INFO] Starting game
Functions#AddBotOutput() - Attempting to add '[INFO] Optimising your experience'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Optimising your experience'
Recvd: [INFO] Optimising your experience
Functions#AddBotOutput() - Attempting to add '[INFO] Starting bot'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Starting bot'
Recvd: [INFO] Starting bot
Functions#AddBotOutput() - Attempting to add '[INFO] Loading game'
Functions#Log() - Attempting to log '[Output Svc] - Received Output from Bot: [INFO] Loading game'
Recvd: [INFO] Loading game