Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Putting a time delay in VB.net

  • 29-01-2007 08:43PM
    #1
    Registered Users, Registered Users 2 Posts: 1,056 ✭✭✭


    I want to delay the call of a procedure by a few seconds (3 seconds or so)


    Me.Show()


    'calls print procedures above
    CaptureScreen()
    prtDocument.Print()


    So after Me.Show () I want to put a few seconds delay in before it calls the CaptureScreen() procedure.

    Any idea how I could do this? Is it even possible?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 1,432 ✭✭✭Merrion




  • Registered Users, Registered Users 2 Posts: 2,157 ✭✭✭dazberry


    As Merrion said:
    System.Threading.Thread.Sleep(3000);

    The only catch is that that will completely freeze your application for the sleep duration. An alternative would be to use a timer (System.Timers.Timer). Example in C#.
    Timer T = new System.Timers.Timer(3000);
    T.AutoReset = false;           
    T.Elapsed += new ElapsedEventHandler(T_Elapsed);
    T.Enabled = true;
    
    // Event Handler
    void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
     if (InvokeRequired)
          Invoke(new ElapsedEventHandler(T_Elapsed),sender,e);
     else
          CaptureScreen();
    }
    
    You might not need the invoke but I put it in there for completeness.

    HTH

    D.


Advertisement