예제 #1
0
 private static ServiceState GetServiceStatus(IntPtr hService)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
     {
         throw new ApplicationException("Failed to query service status.");
     }
     return(sERVICESTATU.dwCurrentState);
 }
예제 #2
0
        private static bool WaitForServiceStatus(IntPtr hService, ServiceState WaitStatus, ServiceState DesiredStatus)
        {
            ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
            ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU);
            if (sERVICESTATU.dwCurrentState == DesiredStatus)
            {
                return(true);
            }
            int tickCount = Environment.TickCount;
            int num       = sERVICESTATU.dwCheckPoint;

            do
            {
Label0:
                if (sERVICESTATU.dwCurrentState != WaitStatus)
                {
                    break;
                }
                int num1 = sERVICESTATU.dwWaitHint / 10;
                if (num1 < 1000)
                {
                    num1 = 1000;
                }
                else if (num1 > 10000)
                {
                    num1 = 10000;
                }
                Thread.Sleep(num1);
                if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
                {
                    break;
                }
                if (sERVICESTATU.dwCheckPoint <= num)
                {
                    continue;
                }
                tickCount = Environment.TickCount;
                num       = sERVICESTATU.dwCheckPoint;
                goto Label0;
            }while (Environment.TickCount - tickCount <= sERVICESTATU.dwWaitHint);
            return(sERVICESTATU.dwCurrentState == DesiredStatus);
        }