I am making a loading screen that flashes while the rest of my application loads. So, I was thinking that I would use system.threading.thread to accomplish this, as I've successfully used this before to handle a file download meter when asyncrously downloading a file. Well, since I had a thread for the meter that part was running syncrously... So. This is the code I've got so far.
My issue is that I want the thread to put itself to sleep or pause for some length of time between blinks. Obviously I need to tell the thread to sleep from itself, not my program, because it must continue to execute code while the meter is frozen. If I use my.application.doevents inside the loop which is the sub which is the thread I'm afraid that the application will cease execution during that time and not my other thread.
Dim myThread As System.Threading.Thread
'Main Loading Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
flagFormLoading = True
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Me.fldDoing.Text = "Loading.."
'Handle Loading Button
Me.btnLoading.Visible = True
myThread = New System.Threading.Thread(AddressOf Flash_BtnLoading)
'...Other things load...
'This is my Thread, it runs seperately from the rest of the program
Private Sub Flash_BtnLoading()
If .Visible = False Then Exit Sub
.BackColor = IIf(.BackColor = Color.MintCream, Color.MediumSpringGreen, Color.MintCream)
Dim timeThen = DateAdd(DateInterval.Second, 1, Now())
myThread.sleep(200) 'Doesn't Work! Gives me an error
Loop Until Now() > timeThen
Loop While .Visible = True
So the other thing I was thinking was to use: My.Application.DoEvents instead of myThread.Sleep(200) but I don't think this is the right approach either. What is the best way to pause a thread in the manner I'm trying to do?
THANKS Experts! ~Michael