I create a background worker from within my class, and in that background worker i want to disable a timer.
I have 2 questions...
1) How can i invoke a delegate method, as i could from a form instance by using Me.Invoke? The Tmr.Enable isnt thread safe is it? Because it lies on a different thread.Do i need to invoke a method on the main thread to perform a thread safe call?
2) I have a TestVariable delcared as public within the module. Is it safe to read/write this variable from different threads within the class? Is there anything i need to be aware of?
Public Class TestClass
Public TestVariable As String
Private WithEvents Tmr As System.Windows.Forms.Timer
Private WithEvents Bw As System.ComponentModel.BackgroundWorker
Public Sub New()
Tmr = New System.Windows.Forms.Timer
Bw = New System.ComponentModel.BackgroundWorker
Tmr.Interval = 5000
Tmr.Enabled = True
Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
If Bw.IsBusy = False Then Bw.RunWorkerAsync()
Private Sub Bw_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Bw.DoWork
If thiscondition = True Then
Tmr.Enabled = False