private static int ServiceHandler(ServiceControl control, int eventType, IntPtr eventData, IntPtr context) { Logger.Log(LogLevel.Debug, "Received control {0} eventType {1} eventData {2} context {3}", control.ToString(), eventType, eventData.ToString(), context.ToString()); OldNativeServiceDispatcher service = (OldNativeServiceDispatcher)GCHandle.FromIntPtr(context).Target; try { switch (control) { case ServiceControl.Interrogate: return 0; case ServiceControl.Stop: return service.OnControl(() => service.OnStop(), ServiceState.StopPending, ServiceState.Stopped); case ServiceControl.Pause: return service.OnControl(() => service.OnPause(), ServiceState.PausePending, ServiceState.Paused); case ServiceControl.Continue: return service.OnControl(() => service.OnContinue(), ServiceState.ContinuePending, ServiceState.Running); case ServiceControl.PowerEvent: return service.OnControl(() => service.OnPowerEvent(eventType, eventData)); case ServiceControl.Shutdown: return service.OnControl(() => service.OnShutdown()); default: return service.OnControl(() => service.OnCustomEvent(control, eventType, eventData)); } } catch (Win32Exception ex) { Logger.Log(LogLevel.Warning, "Win32 error {0} handling control {1}", ex.NativeErrorCode, control.ToString()); return ex.NativeErrorCode; } catch (Exception ex) { Logger.Log(LogLevel.Error, "Uncaught exception {0}\n{1}", ex.Message, ex.ToString()); return 31; } }
private static int ServiceHandler(ServiceControl control, int eventType, IntPtr eventData, IntPtr context) { Logger.Log(LogLevel.Debug, "Received control {0} eventType {1} eventData {2} context {3}", control.ToString(), eventType, eventData.ToString(), context.ToString()); OldNativeServiceDispatcher service = (OldNativeServiceDispatcher)GCHandle.FromIntPtr(context).Target; try { switch (control) { case ServiceControl.Interrogate: return(0); case ServiceControl.Stop: return(service.OnControl(() => service.OnStop(), ServiceState.StopPending, ServiceState.Stopped)); case ServiceControl.Pause: return(service.OnControl(() => service.OnPause(), ServiceState.PausePending, ServiceState.Paused)); case ServiceControl.Continue: return(service.OnControl(() => service.OnContinue(), ServiceState.ContinuePending, ServiceState.Running)); case ServiceControl.PowerEvent: return(service.OnControl(() => service.OnPowerEvent(eventType, eventData))); case ServiceControl.Shutdown: return(service.OnControl(() => service.OnShutdown())); default: return(service.OnControl(() => service.OnCustomEvent(control, eventType, eventData))); } } catch (Win32Exception ex) { Logger.Log(LogLevel.Warning, "Win32 error {0} handling control {1}", ex.NativeErrorCode, control.ToString()); return(ex.NativeErrorCode); } catch (Exception ex) { Logger.Log(LogLevel.Error, "Uncaught exception {0}\n{1}", ex.Message, ex.ToString()); return(31); } }