I have an application I have developed that I will break down into 'simpler' terms just to explain where I am experiencing the problem.
The application has a BackGroundWorker with DoWork, Completed and ProgressChanged Methods. This are located in the 'Main' Class, I then have a 'ScheduledSend' Class that contains code with TimedEvent Handler so that when Time = X it executes the RunWorkerASync for the BGW.
This is because I handle the application both by a forced button press or an out of hours 'scheduled' execute.
I then have a RichTextBox located on the 'Main' Form to display Log information as the process is running.
The Problem When the application is ran using the forced button, the rich textbox log is updated correctly, however when it runs using the scheduled send it does not update at all, can someone please explain to me why this is the case.
I have detailed the code in 'simpler' terms below.
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
So, I have added the Main Form Load, this is where it sets up the timers and such, the Btn Click that 'forces' the process which uses BGWReportProgress correctly and updates the RichTextBox via the ReportProgress Method.
Then the 'ScheduledSend' Class has the 'Timed' Method that when the times of 2 variables match it launches, this DOESN'T update the RichTextBox correctly, the following line:
Main.BGW1BuildXML.ReportProgress(0, "Scheduled Timer Activated...")
Leaves the RichTextbox Blank.
Any help would be appreciated.