Proposed Answer Making a settable time delay in C#

  • Thursday, August 10, 2006 10:59 PM
     
     
    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

All Replies

  • Thursday, August 10, 2006 11:50 PM
     
     Proposed Answer

    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
    •  
  • Tuesday, September 18, 2007 10:38 AM
     
     
    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?
  • Wednesday, June 18, 2008 2:19 PM
     
     
    just add

    this.Refresh();

    it will cause the form to repaint, so you will see the progress 'stepping'
  • Wednesday, January 19, 2011 7:39 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
  • Thursday, August 18, 2011 3:51 AM
     
     
    thank you guys! this.refresh() solved my problem also!
  • Sunday, December 11, 2011 11:32 AM
     
     

    thank guys... my problem also solved with this.Refresh();

    thanks a lot...