Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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;
}

Anybody looking for a graduate programmer (Midlands, England)?
Posted

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;
}

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...