public void CloseDisplay() { Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - called"); try { lock (this.StopMutex) { Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() Stopping DisplayUpdate() Thread"); Thread.Sleep(250); this.stopDisplayUpdateThread = true; goto Label_004E; } Label_0047: Thread.Sleep(100); Label_004E: if (this._displayThread.IsAlive) { goto Label_0047; } Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() DisplayUpdate() Thread stopped."); this._isClosing = true; lock (this.DWriteMutex) { this.GX_Graphics.Dispose(); this.GX_Session.End(); this.GX_Session = null; this.GX_Client.Disconnect(); this.GX_Client = null; this._isOpen = false; } Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - Display closed."); } catch (Exception exception) { Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - caught exception on display close: {0}", new object[] {exception.ToString()}); Log.Error(exception); this._isOpen = false; } }
public bool OpenDisplay(AdvancedSettings UseSettings) { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - called"); this.AdvSettings = UseSettings; MiniDisplayHelper.InitEQ(ref this.EQSettings); MiniDisplayHelper.InitDisplayControl(ref this.DisplaySettings); this.ParseAdvancedSettings(); try { using (Profile.Settings settings = new Profile.MPSettings()) { this._AudioUseASIO = settings.GetValueAsBool("audioplayer", "asio", false); } this.GX_Client = new DCClient(); if (!this.GX_Client.Connect()) { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Could not connect to DriverCore service"); this._isOpen = false; } else { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Connect to the DriverCore service"); this.GX_Devices = this.GX_Client.Devices; if (this.GX_Devices.Count() > 0) { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Found a GX series device"); this.GX_Session = this.GX_Devices[0].CreateSession("MediaPortal"); this.GX_Session.CreateGraphics(out this.GX_Surface); this.GX_Graphics = Graphics.FromImage(this.GX_Surface); this._isOpen = true; this._isClosing = false; Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Display Opened"); this.BacklightOn(); this.GX_Session.SetOptions(true, false); if (this.MOGX_Control.InvertDisplay) { this.GX_Session.SetOptions(true, true); } this.stopDisplayUpdateThread = false; this._displayThread = new Thread(new ThreadStart(this.DisplayUpdate)); this._displayThread.IsBackground = true; this._displayThread.Priority = ThreadPriority.BelowNormal; this._displayThread.Name = "DisplayUpdateThread"; this._displayThread.Start(); if (this._displayThread.IsAlive) { Log.Info("MatrixGX.MOGXDisplay.DisplayUpdate() Thread Started"); } else { Log.Info("MatrixGX.MOGXDisplay.DisplayUpdate() FAILED TO START"); this.CloseDisplay(); } } else { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - No GX Series Display found"); this._isOpen = false; } } } catch (Exception exception) { Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Display not opened - caught exception {0}", new object[] {exception.ToString()}); Log.Error(exception); this._isOpen = false; } Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Completed"); return this._isOpen; }