我有一个我开发的应用程序,我将分解为更简单的'这些术语只是为了解释我遇到问题的地方。
该应用程序具有带有DoWork,Completed和ProgressChanged方法的BackGroundWorker。它位于' Main'上课,然后我有一个' ScheduledSend'包含TimedEvent Handler代码的类,以便在Time = X时执行BGW的RunWorkerASync。
这是因为我通过强制按钮或非工作时间来处理应用程序'执行。
然后我在' Main'上有一个RichTextBox。用于在进程运行时显示日志信息的表单。
问题 当使用强制按钮运行应用程序时,富文本框日志会正确更新,但是当它使用预定发送运行时它根本不会更新,有人可以向我解释为什么会出现这种情况。
我详细介绍了简单的代码'以下条款。
Public Class Main
'Timer Variables
Private Shared aTimer As System.Timers.Timer
Private Shared aTimerTime As Integer
Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
'Setup the Scheduled Send Timers
aTimerTime = (1000)
aTimer = New System.Timers.Timer(aTimerTime) '1000 = 1 second, 60000 = 1 minute
AddHandler aTimer.Elapsed, AddressOf ScheduledSend.OnTimedEvent
aTimer.Enabled = True
End Sub
Private Sub SendManFileBtn_Click(sender As Object, e As EventArgs) Handles SendManFileBtn.Click
Try
LogFileRTB.Text = ""
TSProgBar.MarqueeAnimationSpeed = 100
BGW1BuildXML.RunWorkerAsync()
Catch ex As Exception
ErrorLogging.ReportError(ex)
End Try
End Sub
Private Sub BGW1BuildXML_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BGW1BuildXML.ProgressChanged
Try
LogFileRTB.AppendText(DateTime.Now.ToLongTimeString & " " & e.UserState.ToString & Environment.NewLine)
Catch ex As Exception
ErrorLogging.ReportError(ex)
End Try
End Sub
End Class
Public Class ScheduledSend
Public Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
Try
Console.WriteLine(e.SignalTime.ToLongTimeString)
Console.WriteLine(My.Settings.schTimer.ToLongTimeString)
If e.SignalTime.ToLongTimeString = My.Settings.schTimer.ToLongTimeString Then
Console.WriteLine("Scheduled Timer Activated...")
Main.BGW1BuildXML.ReportProgress(0, "Scheduled Timer Activated...")
Main.BGW1BuildXML.RunWorkerAsync()
End If
Catch ex As Exception
ErrorLogging.ReportError(ex)
End Try
End Sub
End Class
所以,我已经添加了主表单加载,这是它设置计时器的地方等等,Btn点击“强制”'正确使用BGWReportProgress并通过ReportProgress方法更新RichTextBox的过程。
然后' ScheduledSend'班级有“定时”和“定时”。当2个变量的时间匹配启动时,此 DOESN' T 正确更新RichTextBox,如下所示:
Main.BGW1BuildXML.ReportProgress(0, "Scheduled Timer Activated...")
将RichTextbox留空。
任何帮助都将不胜感激。