//*************************************************************************** // Private Methods // private void Init() { this._state = RenderState.InitializingDevice; try { this._devCtx = Unmanaged.DeviceContext.GetWindow(this._hwnd); this._gfx = this._devCtx.GetGraphics(); this._gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; this._gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; this._gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; this._gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; this._gfx.Clear(this._bgColor); this._bounds = Unmanaged.Win32.GetWindowRect(this._hwnd); this.yCenter = this._bounds.Height / 2; this.xCenter = this._bounds.Width / 2; this._scrnSize = (int)((System.Math.Min(this._bounds.Height, this._bounds.Width) / 2) * 0.9); this._drawThread = new Thread(new ThreadStart(this.DrawingThreadWorker)); this._drawThread.IsBackground = true; // We need to sleep this thread until the preview window is visible. DateTime dtWaitStart = DateTime.Now; while (Unmanaged.Win32.IsWindowVisible(this._hwnd) == false) { Thread.CurrentThread.Join(200); if (DateTime.Now.Subtract(dtWaitStart).TotalSeconds > 15) { break; } } if (!Unmanaged.Win32.IsWindowVisible(this._hwnd)) { throw new Exception("Timeout period reached, waiting for window to become visible."); } this.ResetVars(); this._state = RenderState.Ready; } catch (Exception ex) { this.OnException(new ExceptionEventArgs(ex)); this._state = RenderState.RenderError; } }
protected virtual void Dispose(bool disposing) { if (this._disposed) { return; } if (disposing) { if (this._shuttingDown) { this.Stop(); } this._gfx.Dispose(); this._devCtx.Dispose(); } this._drawThread = null; this._gfx = null; this._devCtx = null; this._disposed = true; }