snufse Posted July 28, 2006 Posted July 28, 2006 I have an application that loops through a set of code a certain number of times. After each loop I need to pause the process for number of seconds and then iterate through the loop again. In VB 2003 I used Thread. Sleep(no of seconds) and it worked fine. I also used Thread.Suspend and Resume which are not supported in VB 2005. Any ideas how I can do the same in VB 2005 without using Threading? Thanks. Quote
Cags Posted July 28, 2006 Posted July 28, 2006 Perhaps something like this would suit your purposes.... Timer myTimer = new Timer(); myTimer.Tick += new EventHandler(myTimer_Tick); private void myTimer_Tick(object sender, System.EventArgs e) { timer1.Enabled = false; // your loop code timer1.Interval = 100; // whatever time you wanna wait timer1.Enabled = true; } Quote Anybody looking for a graduate programmer (Midlands, England)?
snufse Posted August 4, 2006 Author Posted August 4, 2006 TimerObject It worked. I had to tweek it a little (running VB). Here is the code: Public Sub myTimeHandler(ByVal sender As Object, ByVal e As EventArgs) myTimer.Stop() If myLoopCounter < myLoopNumber Then ListBox1.Items.Add("Hello World") 'example but code goes here myLoopCounter += 1 myTimer.Start() 'or use the myTimer.Enabled = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click AddHandler myTimer.Tick, AddressOf myTimeHandler myTimer.Interval = 1000 'milliseconds myTimer.Start() 'or use the myTimer.Enabled = True End Sub Perhaps something like this would suit your purposes.... Timer myTimer = new Timer(); myTimer.Tick += new EventHandler(myTimer_Tick); private void myTimer_Tick(object sender, System.EventArgs e) { timer1.Enabled = false; // your loop code timer1.Interval = 100; // whatever time you wanna wait timer1.Enabled = true; } Quote
pcf108 Posted September 8, 2006 Posted September 8, 2006 You might also want to try... System.Threading.Thread.Sleep() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.