Пример #1
0
        public void ServiceMainCallback(int argCount, IntPtr argPointer)
        {
            LPHANDLER_FUNCTION_EX handler = new LPHANDLER_FUNCTION_EX(Win32HandlerFn);

            // handler needs to last until the service stops

            service_handle = RegisterServiceCtrlHandlerEx(ServiceName ?? "", handler, IntPtr.Zero);

            if (service_handle != IntPtr.Zero)
            {
                SetStatus(ServiceControllerStatus.StartPending);

                stop_event = new ManualResetEvent(false);

                string[] args = new string[argCount];
                for (int i = 0; i < argCount; i++)
                {
                    IntPtr arg = Marshal.ReadIntPtr(argPointer, IntPtr.Size * i);
                    args[i] = Marshal.PtrToStringUni(arg);
                }

                OnStart(args);

                SetStatus(ServiceControllerStatus.Running);

                stop_event.WaitOne();

                SetStatus(ServiceControllerStatus.StopPending);

                OnStop();

                SetStatus(ServiceControllerStatus.Stopped);
            }
        }
Пример #2
0
 private static extern IntPtr RegisterServiceCtrlHandlerEx(
     string lpServiceName,
     LPHANDLER_FUNCTION_EX lpHandlerProc,
     IntPtr lpContext);
Пример #3
0
		public void ServiceMainCallback (int argCount, IntPtr argPointer)
		{
			LPHANDLER_FUNCTION_EX handler = new LPHANDLER_FUNCTION_EX (Win32HandlerFn);
			// handler needs to last until the service stops

			service_handle = RegisterServiceCtrlHandlerEx (ServiceName ?? "", handler, IntPtr.Zero);

			if (service_handle != IntPtr.Zero)
			{
				SetStatus (ServiceControllerStatus.StartPending);
				
				stop_event = new ManualResetEvent (false);

				string[] args = new string[argCount];
				for (int i=0; i<argCount; i++)
				{
					IntPtr arg = Marshal.ReadIntPtr (argPointer, IntPtr.Size * i);
					args[i] = Marshal.PtrToStringUni (arg);
				}

				OnStart (args);

				SetStatus (ServiceControllerStatus.Running);

				stop_event.WaitOne ();

				SetStatus (ServiceControllerStatus.StopPending);

				OnStop ();

				SetStatus (ServiceControllerStatus.Stopped);
			}
		}
Пример #4
0
 public static unsafe extern IntPtr RegisterServiceCtrlHandlerEx(
     string lpServiceName,
     LPHANDLER_FUNCTION_EX lpHandlerProc,
     void* lpContext);
Пример #5
0
		private static extern IntPtr RegisterServiceCtrlHandlerEx (
			string lpServiceName,
			LPHANDLER_FUNCTION_EX lpHandlerProc,
			IntPtr lpContext);