스레드의 sleep 메소드는 특정 기간 동안 스레드를 일시 중지하는 데 사용됩니다.
몇 초 동안 절전 모드를 설정하려면 다음 코드 스니펫과 같이 사용하십시오 -
int sleepfor = 2000; Thread.Sleep(sleepfor);
스레드의 절전 방법을 구현하기 위해 다음 코드를 실행할 수 있습니다 -
예
using System;
using System.Threading;
namespace MyApplication {
class ThreadCreationProgram {
public static void CallToChildThread() {
Console.WriteLine("Child thread starts");
int sleepfor = 2000;
Console.WriteLine("Child Thread Paused for {0} seconds", sleepfor / 1000);
Thread.Sleep(sleepfor);
Console.WriteLine("Child thread resumes");
}
static void Main(string[] args) {
ThreadStart childref = new ThreadStart(CallToChildThread);
Console.WriteLine("In Main: Creating the Child thread");
Thread childThread = new Thread(childref);
childThread.Start();
Console.ReadKey();
}
}
} 출력
In Main: Creating the Child thread Child thread starts Child Thread Paused for 2 seconds Child thread resumes