none
Making a settable time delay in C#

    Question

  • Is it possible to make a delay in the C# code such that if I wanted to make it possible to have a 3 second delay at certain points in the code that would simply hold the code for 3 seconds and then continue on again?  I am trying to make a program that will take measurements and I need it to run the lab instrument for a set time, and not progress in the code while it is running.  I would also like to be able to change the time delay from the user interface rather than having to change the code.
    Thanks,
    SVandal
    Thursday, August 10, 2006 10:59 PM

All replies

  • You can pause current app thread by using this code:

    System.Threading.Thread.Sleep(3000);

     

    • Proposed as answer by Chris Quon Friday, June 20, 2008 4:01 PM
    Thursday, August 10, 2006 11:50 PM
  • Why then if I use "System.Threading.Thread.Sleep(3000);" inside a cycle applying it to every step I get ...
    {
    begin
    big pause
    final result
    }

    ... without any middle positions?
    Tuesday, September 18, 2007 10:38 AM
  • just add

    this.Refresh();

    it will cause the form to repaint, so you will see the progress 'stepping'
    Wednesday, June 18, 2008 2:19 PM
  • Hi Thanks a lot I was struggling with my program for the same problem and your advice for using refresh solved it. God bless U
    Wednesday, January 19, 2011 7:39 PM
  • thank you guys! this.refresh() solved my problem also!
    Thursday, August 18, 2011 3:51 AM
  • thank guys... my problem also solved with this.Refresh();

    thanks a lot...

    Sunday, December 11, 2011 11:32 AM