윈폼에는 Timer 라는 컨트롤이 있었는데 WPF에는 없다

using System.Windows.Forms 를 사용해 윈폼의 타이머를 사용해도 되지만

WPF의 타이머를 사용해보도록 하겠다


using System.Windows.Threading 을 사용한다


DispatcherTimer timer = new DispatcherTimer();    //객체생성


timer.Interval = TimeSpan.FromMilliseconds(0.01);    //시간간격 설정

timer.Tick += new EventHandler(timer_Tick);          //이벤트 추가

timer.Start();                                       //타이머 시작. 종료는 timer.Stop(); 으로 한다


private void timer_Tick(object sender, EventArgs e)
{
    //여기에 실행시킬 구문을 입력하면 된다
}

종료

Process.Start("shutdown.exe", "-s"); // 기본적으로 30초 후 종료

Process.Start("shutdown.exe", "-s -t xx") // xx 초 후 종료

재부팅

Process.Start("shutdown.exe","-r"); // 종료과 유사하며 커멘드만 "-r"을 사용

Process.Start("shutdown.exe","-r -t xx");

로그오프

Process.Start("shutdown.exe","-l"); // 위 코드와 유사하며 커멘드만 "-l"(숫자 1이 아닌 소문자'l')을 사용


출저 : http://www.isfull.com

'Programming language > C#' 카테고리의 다른 글

c# 실행중인 프로그램 조회, 강제종료  (0) 2016.03.25