private static void CloseMsgHandler() { if (_msgHandler == null) { return; } try { _msgHandler.Dispose(); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error(ex); } _msgHandler = null; }
private static void InitMsgHandler() { if (_msgHandler != null) { return; } ServiceRegistration.Get <ILogger>().Debug("Initializing Message Handler"); try { _msgHandler = new RawMessageHandler(); _msgHandler.OnStartRequest += (s, e) => { ILogger logger = ServiceRegistration.Get <ILogger>(); logger.Info("Received StartButton press"); Process[] processes = Process.GetProcessesByName("MP2-Client"); if (processes.Length == 0) { logger.Info("MP2-Client is not running - starting it."); StartClient(); } else if (processes.Length == 1) { logger.Info("MP2-Client is already running - switching focus."); SwitchFocus(); } else { logger.Info("More than one window named 'MediaPortal' has been found!"); foreach (Process procName in processes) { logger.Debug("MPTray: {0} (Started: {1}, ID: {2})", procName.ProcessName, procName.StartTime.ToShortTimeString(), procName.Id); } } }; } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error(ex); } }