private int ServiceCommandCallbackEx(int command, int eventType, IntPtr eventData, IntPtr eventContext) { switch (command) { case ControlOptions.CONTROL_POWEREVENT: { ThreadPool.QueueUserWorkItem(_ => DeferredPowerEvent(eventType, eventData)); break; } case ControlOptions.CONTROL_SESSIONCHANGE: { // The eventData pointer can be released between now and when the DeferredDelegate gets called. // So we capture the session id at this point WTSSESSION_NOTIFICATION sessionNotification = new WTSSESSION_NOTIFICATION(); Marshal.PtrToStructure(eventData, sessionNotification); ThreadPool.QueueUserWorkItem(_ => DeferredSessionChange(eventType, sessionNotification.sessionId)); break; } default: { ServiceCommandCallback(command); break; } } return(0); }
private Int32 ServiceCommandCallbackEx(ControlOptions command, Int32 eventType, IntPtr eventData, IntPtr eventContext) { if (command != ControlOptions.PowerEvent && command != ControlOptions.SessionChange && command != ControlOptions.Interrogate) { XTrace.WriteLine("ServiceCommandCallbackEx(command={0}, eventType={1}, eventData={2:x}, eventContext={3:x})", command, eventType, eventData, eventContext); } switch (command) { case ControlOptions.Interrogate: ReportStatus(_status.currentState, 0, false); break; case ControlOptions.Stop: case ControlOptions.Shutdown: ReportStatus(ServiceControllerStatus.StopPending); ThreadPoolX.QueueUserWorkItem(() => { try { _service.StopLoop(); } catch (Exception ex) { XTrace.WriteException(ex); } ReportStatus(ServiceControllerStatus.Stopped); }); break; case ControlOptions.PowerEvent: XTrace.WriteLine("PowerEvent {0}", (PowerBroadcastStatus)eventType); break; case ControlOptions.SessionChange: var sessionNotification = new WTSSESSION_NOTIFICATION(); Marshal.PtrToStructure(eventData, sessionNotification); XTrace.WriteLine("SessionChange {0}, {1}", (SessionChangeReason)eventType, sessionNotification.sessionId); break; case ControlOptions.TimeChange: var time = new SERVICE_TIMECHANGE_INFO(); Marshal.PtrToStructure(eventData, time); XTrace.WriteLine("TimeChange {0}=>{1}", DateTime.FromFileTime(time.OldTime), DateTime.FromFileTime(time.NewTime)); break; default: ReportStatus(_status.currentState); break; } return(0); }