728x90
반응형
728x170
using System;
using System.ServiceProcess;
#region 서비스 재시작하기 - RestartService(serviceName, timeOut)
/// <summary>
/// 서비스 재시작하기
/// </summary>
/// <param name="serviceName">서비스명</param>
/// <param name="timeOut">타임아웃 (밀리초)</param>
public void RestartService(string serviceName, int timeOut)
{
ServiceController serviceController = new ServiceController(serviceName);
try
{
int tickCount1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeOut);
serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
int tickCount2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeOut - (tickCount2 - tickCount1));
serviceController.Start();
serviceController.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
}
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] Nullable 타입 여부 구하기 (0) | 2016.07.05 |
---|---|
[C#/COMMON] Nullable 클래스 : GetUnderlyingType 정적 메소드를 사용해 기본 타입 구하기 (0) | 2016.07.05 |
[C#/COMMON] AssemblyInstaller 클래스 : 윈도우즈 서비스 설치 취소하기 (0) | 2016.06.12 |
[C#/COMMON] AssemblyInstaller 클래스 : 윈도우즈 서비스 설치하기 (0) | 2016.06.12 |
[C#/COMMON] ServiceController 클래스 : 윈도우즈 서비스 설치 여부 구하기 (0) | 2016.06.12 |
[C#/COMMON] ServiceController 클래스 : 윈도우즈 서비스 중단하기 (0) | 2016.06.12 |
[C#/COMMON] ServiceController 클래스 : 윈도우즈 서비스 시작하기 (0) | 2016.06.12 |
[C#/COMMON] EventLog 클래스 : 이벤트 로그 사용하기 (0) | 2016.06.12 |
[C#/COMMON] 쓰기/읽기 작업을 비동기 순차 처리하기 (0) | 2016.06.09 |
[C#/COMMON] Timer 클래스 사용하기 (0) | 2016.06.04 |
댓글을 달아 주세요