我一直在为系统编写一些代码,并且需要在 VB.NET 中使用线程而不是普通计时器。
它工作正常,但问题在于闪烁时间,当单击按钮时它会按预期闪烁,如果在测试中多次单击它,则闪烁时间大致乘以原始睡眠线程时间(750ms),这继续每次点击都会发生。
我该怎么做才能使眨眼不加快?下面是代码!
Private _flash As Boolean = False
Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
_flash = True
Dim FlashThread As New Thread(New ThreadStart(AddressOf FlashLabel))
FlashThread.Start()
End Sub
Private Sub FlashLabel()
Dim _color As Color = Color.Gray
While _flash
If label1.ForeColor.Equals(_color) Then
label1.ForeColor = Color.Red
Else
label1.ForeColor = Color.Gray
System.Threading.Thread.Sleep(750)
End While
End Sub