frenchie
frenchie

Reputation: 51997

Adding Delay in application (for debugging)

I'd like to add a delay between 2 lines of code because I'm testing an updateprogress template. Ideally, the one-liner.

Thanks.

Upvotes: 3

Views: 2922

Answers (7)

Guillaume86
Guillaume86

Reputation: 14400

you're looking for

Thread.Sleep(2000) 

Upvotes: 1

Sogger
Sogger

Reputation: 16142

System.Threading.Thread.Sleep(int time_ms); //One line, no 'using' :)

Upvotes: 0

Abe Miessler
Abe Miessler

Reputation: 85106

Try the Sleep method. Example:

Thread.Sleep(3000); //3 seconds

You will need to add this using directive:

using System.Threading;

to get access to the method.

The parameter you pass it is the number of milliseconds you want to suspend the current thread.

Upvotes: 9

Carlos Valenzuela
Carlos Valenzuela

Reputation: 834

You could put that line in a condition, that will only be 'true', passing that amount of time, using the delay method: Thread.Sleep(time)

Upvotes: 0

Scott M.
Scott M.

Reputation: 7347

try using Thread.Sleep()

Upvotes: 0

Martin Buberl
Martin Buberl

Reputation: 47164

You're looking for the Thread.Sleep method and Preprocessor Directives:

#if DEBUG
    Thread.Sleep(1000);
#endif

Upvotes: 1

CodesInChaos
CodesInChaos

Reputation: 108830

You might want to use Thread.Sleep. It takes the time to sleep in milliseconds

Thread.Sleep(10000);//Waits 10 seconds.

Upvotes: 0

Related Questions