Pause Code

pschuler123

New member
Joined
Jan 5, 2005
Messages
1
Programming Experience
Beginner
I have a form with a number of label controls on it. Based on a click event I would like the label controls backcolor property to change. I want a five second delay between each change. I have tried adding a timer control and enabling it in the click event with the interval property set to 5000. This does nothing. Tried using the following code:

For n = 1 To daysComplete()
LabelArray(n).BackColor = System.Drawing.Color.Red
LabelArray(n).Text = n
System.Threading.Thread.CurrentThread.Sleep(5000)
System.Threading.Thread.CurrentThread.Resume()
Next n

This caused the application to go into a 'Not Responding' status and I had to end task. I'm assuming this is the wrong place to insert this code. Anyone have any ideas. Thanks.

This ended up working for me. Thanks

For n = 1 To daysComplete()
LabelArray(n).BackColor = System.Drawing.Color.Red
LabelArray(n).Text = n
System.Threading.Thread.CurrentThread.Sleep(3000)
System.Windows.Forms.Application.DoEvents()
Next n
 
Last edited:
If you use the timer you need to use the tick event. I've never used sleep, but I belive you need to add DoEvents in there so you prog. doesn't hang.

TPM
 
VB.NET:
 private sub Timer1_Tick(...) Handles Timer1.Tick
 static n as integer=0
                LabelArray(n).BackColor = Color.Red
                LabelArray(n).Text = n.ToString
 if n >= DaysComplete then Timer1.Enabled=False
 end sub
 
Back
Top