Halt/Pause an Application for period of time

snufse

Newcomer
Joined
Jan 30, 2004
Messages
10
Location
west palm beach
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.
 
Perhaps something like this would suit your purposes....
C#:
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;
}
 
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








Cags said:
Perhaps something like this would suit your purposes....
C#:
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;
}
 
Back
Top