wait function in vb.net

vb.net India
  • 13 years ago

    Hi!

    if anyone know  wait function  in vb.net window application  plz send  me 

    i want  to stop my function for perticular time period  any solution ? send me

    bye

     

  • 13 years ago

    The only "wait" function I know of is 'system.threading.thread.sleep'.  However, this will hang the UI if you call it on the main thread.  So unless your using multiple threads and this code is running on non UI thread I wouldn't use it.  If your code is running on the UI thread you have two options that I can think of.  Try to re-work your code and instead use a timer to fire off the desired code at the right time, or create your own wait function.

        ' Loops for a specificied period of time (milliseconds)
        Private Sub wait(ByVal interval As Integer)
            Dim sw As New Stopwatch
            sw.Start()
            Do While sw.ElapsedMilliseconds < interval
                ' Allows UI to remain responsive
                Application.DoEvents()
            Loop
            sw.Stop()
        End Sub
  • 13 years ago

    OK FINE ..

    AND Thanks lot!

  • 13 years ago
    System.Threading.Thread.CurrentThread.Sleep(1000)

    'It should sleep for 1000ms (1 sec)

    Hope this helps, Happy coding =)

    (Check out System.Threading library)







Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski