我有一个程序可以启动java JAR文件并在运行时抓取输出; (来自PowerBot.org的RSBot) 一切正常但我的ListView不是从“OutputDataReceived”事件中添加文本但我可以在MessageBox.Show()中显示它。或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
函数类(如上所用)
Public Class Functions
Public Shared Sub Log(supplier As String, msg As String)
Dim s(2) As String
s(0) = DateTime.Now.ToString("HH:mm:ss-fff")
s(1) = supplier
s(2) = msg
frmLog.GhostListView1.Items.Add(New ListViewItem(s))
End Sub
Public Shared Sub AddBotOutput(Args As DataReceivedEventArgs)
Dim s(1) As String
s(0) = DateTime.Now.ToString("HH:mm:ss-fff")
s(1) = Args.Data
frmBotOutput.GhostListView1.Items.Add(New ListViewItem(s))
End Sub
End Class
调试中的输出
Recvd: [INFO] Optimising your experience
Recvd: [INFO] Starting bot
Recvd: [INFO] Loading game
Recvd: [INFO] Unpacking client (7dea8f)
Recvd: [INFO] Starting game
但是,我的ListView是空白的,项目数是0 ...... 我有点迷失在这里,我有一种感觉,问题是盯着我的脸,但我一直在努力压扁这个虫子大约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