i will be grateful if somebody will explain to me why this code that i wrote is not executing on another thread (the code just executing Button4_Click sub without any exception). if i`m calling timerclass() sub from the main thread everything is running perfect. i cant understand this behavior.. maybe i need to use delegate(?)
Private t As System.Threading.Thread
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
t = New System.Threading.Thread(AddressOf timerclass)
t.Start()
End Sub
Private TargetDT As DateTime
Private CountDownFrom As TimeSpan = TimeSpan.FromMinutes(3)
Private Sub timerclass()
tim = New Timer
AddHandler tim.Tick, AddressOf tim_Tick
tim.Interval = 500
tim.Interval = 500
TargetDT = DateTime.Now.Add(CountDownFrom)
tim.Start()
End Sub
Private Sub tim_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
If ts.TotalMilliseconds > 0 Then
Label2.Text = ts.ToString("mm\:ss")
Else
Label2.Text = "00:00"
tim.Stop()
MessageBox.Show("Done")
End If
End Sub