Codit Develop
Codit Develop
Codit Develop
전체 방문자
오늘
어제
  • 분류 전체보기 (146)
    • IT (1)
      • 스마트폰 (1)
    • Game (59)
      • DNF (0)
      • StarCraft2 (11)
      • LostArk (45)
      • Minecraft (3)
      • Elyon (0)
    • Develop (43)
      • Web (15)
      • PHP (2)
      • Laravel (0)
      • C# (11)
      • NodeJS (1)
      • Java (2)
      • Python (1)
      • Cordova (3)
      • Android (0)
      • WPF (1)
      • PowerShell (5)
      • Other (2)
      • Javascript (0)
    • OS (17)
      • Windows (6)
      • Linux (11)
    • Product (17)
      • Docker (10)
      • GitLab (3)
      • NuGet (2)
      • Git (1)
      • Nginx (1)
    • DB (7)
      • All-DB (2)
      • MariaDB (2)
      • MySQL (2)
      • Oracle (0)
      • MSSQL (1)
      • Cubrid (0)
    • PC (2)
      • 견적함 (2)
      • 정보 (0)

블로그 메뉴

    공지사항

    인기 글

    태그

    • jQuery
    • db
    • 모험의
    • MySQL
    • 몬스터
    • 조합
    • 개인복권디펜스
    • web
    • 뷰포인트
    • 씨앗
    • JavaScript
    • c#
    • 스타2
    • 모코코
    • 숨겨진
    • Linux
    • 유디아
    • html
    • 모험의 서
    • 모험의서
    • 서
    • 디펜스
    • 오즈혼
    • 개복디
    • 로스트아크
    • 아르테미스
    • docker
    • css
    • 구릉지
    • 히든

    최근 댓글

    최근 글

    티스토리

    hELLO · Designed By 정상우.
    Codit Develop

    Codit Develop

    Develop/C#

    [C#] 서비스 제어하기 (시작 / 종료 / 상태 검사)

    2019. 4. 2. 18:38
    반응형
    using System.ServiceProcess;
    
    private void Service_Control_Function(){
        ServiceController sc = new ServiceController("Service Name");
    
        //ServiceControllerStatus.Running : 서비스 실행 상태
        //ServiceControllerStatus.StartPending : 서비스 시작 중
        //ServiceControllerStatus.Stopped : 서비스 정지 상태
        //ServiceControllerStatus.StopPending : 서비스 중지 중
        //ServiceControllerStatus.Paused : 서비스 일시정지 상태
        //ServiceControllerStatus.PausePending : 서비스 일시정지 중
        //ServiceControllerStatus.ContinuePending : 서비스 다시시작 중
    
    
        if(sc.Status == ServiceControllerStatus.Running) //해당 서비스가 실행중인지 확인
        {
    
        }
        else if(sc.Status == ServiceControllerStatus.Stopped) //
        {
    
        }
        //.....
    
        //검색한 서비스가 Running 상태가 될 때 까지 대기.
        sc.WaitForStatus(ServiceControllerStatus.Running);    
    
        sc.Start();        //검색한 서비스 시작
        sc.Stop();      //검색한 서비스 중지
        sc.Pause();     //검색한 서비스 일시정지
        sc.Continue();     //검색한 서비스 다시 시작
    
        //검색한 서비스가 중지 가능한 상태인지 확인 이후 정지.
        if(sc.CanStop)
        {
            sc.Stop();
        }
    }
    반응형
    저작자표시 비영리 변경금지 (새창열림)

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

    [C#] EUC-KR Encoding 추가  (2) 2021.04.28
    [C#] Thread 에서 Main Thread 간섭하기.  (0) 2019.04.02
    [C#] 예외 처리 (try - catch - finally)  (0) 2019.04.02
    [C#] bat 파일 실행할 때 로그를 Listbox에 넣기  (0) 2019.03.11
    [C#] Thread에 값 전달하기  (0) 2019.01.09
      'Develop/C#' 카테고리의 다른 글
      • [C#] EUC-KR Encoding 추가
      • [C#] Thread 에서 Main Thread 간섭하기.
      • [C#] 예외 처리 (try - catch - finally)
      • [C#] bat 파일 실행할 때 로그를 Listbox에 넣기
      Codit Develop
      Codit Develop
      내가 보려고 만든 개발 블로그

      티스토리툴바