Hi There,
I have a thread which executes a class. I have another thread which starts a timer (system.timers.time). I also have a textbox on the form which, when the elapsed event of the timer is called, will increment.
Basically, what I want to be able to do is graphically represent to the user that the process is running (because this process can take several hours to run), and to display the elapsed time.
The problem I have, is that the class thread starts, and then the timer thread starts; and the timer clicks over a few increments, and then doesn't get called for a while (while the class is being executed), and then, once the class has finished executing, the timer 'catches up', and quickly increments to the actual elapsed time, and then all threads are stopped as a result of calling the FinishedLoading event handler.
I don't know how I should call get this working so that the timer can continue to increment whilst the class is being executed.
My code snippet is as follows:
Please try and respond asap with some assistance.
Thanks very much,
Michelle
I have a thread which executes a class. I have another thread which starts a timer (system.timers.time). I also have a textbox on the form which, when the elapsed event of the timer is called, will increment.
Basically, what I want to be able to do is graphically represent to the user that the process is running (because this process can take several hours to run), and to display the elapsed time.
The problem I have, is that the class thread starts, and then the timer thread starts; and the timer clicks over a few increments, and then doesn't get called for a while (while the class is being executed), and then, once the class has finished executing, the timer 'catches up', and quickly increments to the actual elapsed time, and then all threads are stopped as a result of calling the FinishedLoading event handler.
I don't know how I should call get this working so that the timer can continue to increment whilst the class is being executed.
My code snippet is as follows:
Code:
public Thread1 as Threading.Thread
public ThreadTimer as Threading.Thread
private event FinishedLoading()
dim Timer as Timers.Timer
Public Sub New(byval parent as frmMain)
Thread1 = new System.Threading.Thread(AddressOf CreateDDBatch)
ThreadTimer = new System.Threading.Thread(AddressOf Timer1Start)
AddHandler FinishedLoading, AddressOf FinishedLoadingEH
Thread1.Start()
ThreadTimer.Start()
End Sub
Private Sub CreateDDBatch()
Dim DDProcessor as new clsID_DD_AutoProcessor(username, password)
RaiseEvent FinishedLoading()
End Sub
Sub FinishedLoadingEH()
ThreadTimer.Abort()
Timer1.Stop()
Me.Cursor = Windows.Forms.Cursors.Default
Me.btnClose.Enabled = True
Thread1.Abort()
End Sub
Private Sub Timer1Start()
Timer = New System.Timers.Timer(100)
AddHandler Timer.Elapsed, AddressOf TimerTick
Timer.Start()
End Sub
Private Sub TimerTick(ByVal sender as Object, ByVal e as Timers.ElapsedEventArgs)
Try
tbTimer.text = cint(tbTimer.text) + 1
Catch ex as Exception
End Try
End Sub
Please try and respond asap with some assistance.
Thanks very much,
Michelle