Tell me how you can pause the program for a while?
System.Threading.Thread.Sleep (500);
Answer 1, authority 100%
Sample Approach:
- start a new thread,
- enter a loop in the stream,
- in a loop to do work and fall asleep for a while.
Code example:
using System;
using System.Threading;
public class ThreadExample {
public static void ThreadProc () {
while (true) {
// TODO: This does what needs to be done
Thread.Sleep (1000);
}
}
public static void Main () {
Thread t = new Thread (new ThreadStart (ThreadProc));
t.Start ();
Thread.Sleep (1000);
t.Join ();
}
}
Answer 2, authority 50%
System.Windows.Threading.DispatcherTimer // for WPF interface
System.Timers.Timer
System.Web.UI.Timer
System.Threading.Timer
Microsoft.Win32.SystemEvents.CreateTimer (int) + (Microsoft.Win32.SystemEvents.TimerElapsed)
- create timer
- Set spacing
- Subscribe to
Tick, Elapsed, etc
Start ()
There is also an interesting class. It is called Stopwatch
. This is a stopwatch in Russian. Accuracy depends on processor clock speed