Help me! the Timer could not be enabled!!!

Y

yxq

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
CheckThread = New Thread(New ThreadStart(AddressOf MyThread))
CheckThread.IsBackground = True
CheckThread.Start()
End Sub

Private Sub MyThread()
'
'
'
'
Timer1.Enabled = True
End Sub

But MyThread could not be started again! Thank you
 
H

Herfried K. Wagner [MVP]

yxq said:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
CheckThread = New Thread(New ThreadStart(AddressOf MyThread))
CheckThread.IsBackground = True
CheckThread.Start()
End Sub

Private Sub MyThread()
'
'
'
'
Timer1.Enabled = True
End Sub

Instance members of 'System.Windows.Forms.Timer' are not guaranteed to be
thread-safe. Thus you cannot directly access them from another thread. I
suggest to read the articles listed in the document referenced below:

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top