views:

56

answers:

2

Are there any Timeout.bas equivalents for Visual Basic using Visual Studio 2010

I have this file called timeout.bas that I could add to projects in earlier versions of visual basic that basically let me use the code:

Timeout .5

I'm trying to get the same kind of file for Visual Studio 2010

So I can write code such as:

Label1.text = "hello"
Timeout 1 
label1.text = "good day!"

It's basically just a pause or delay.... Thanks in advance!

+1  A: 

Here's an idea that might work... try re-writing timeout() in VB.NET:

NOTE: Below is untested pseudocode, specifically the time stuff. Maybe write a unit-test or so to see if this will work.

Sub timeout(duration)
     DateTime endtime = DateTime.Now().AddMilliseconds(duration)
     Do While DateTime.Now() < endtime
         Application.DoEvents()
     Loop 
End Sub
sheepsimulator
+1  A: 

Here how to do it with a Timer. You have to split your original routine into two parts.

Public Class Form1

  Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
    TextBox1.Text = "hi"

    Dim tmr As New Timer
    tmr.Enabled = True
    tmr.Interval = 3000 ' milliseconds '
    AddHandler tmr.Tick, AddressOf ContinueWork
  End Sub

  Sub ContinueWork()
    TextBox1.Text = "hi2"
  End Sub

End Class

Be aware that the user can continue to click around your application while the timer interval is running.

I am not sure why you would want to do this, it seems odd behaviour for an application, but I'm sure you have your own good reasons!

MarkJ