Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Putting a time delay in VB.net

Options
  • 29-01-2007 9:43pm
    #1
    Registered Users Posts: 1,052 ✭✭✭


    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 Posts: 1,421 ✭✭✭Merrion




  • Registered Users Posts: 2,150 ✭✭✭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