public void Attach(IntPtr hwnd) { if (hwnd == IntPtr.Zero) { throw new ArgumentNullException("hwnd"); } lock (_syncRoot) { if (_window != null) { throw new InvalidOperationException("Already attached!"); } ErrorMessage = null; IsRendering = false; _window = CreateSubclassWindow(hwnd); _good.Clear(); _isRunning = true; _thread = new Thread(RenderThreadProc); _thread.IsBackground = false; _thread.Start(); } }
private SubclassWindow CreateSubclassWindow(IntPtr hwnd) { var window = new SubclassWindow(this); var failed = false; try { window.AssignHandle(hwnd); return(window); } catch (Exception ex) { failed = true; ErrorMessage = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); throw; } finally { if (failed) { window.ReleaseHandle(); } } }
public void Detach() { IsRendering = false; Thread thread = null; SubclassWindow window = null; lock (_syncRoot) { window = _window; _window = null; thread = _thread; _thread = null; _isRunning = false; } // wait&release outside lock to avoid deadlock if (thread != null && thread.IsAlive) { thread.Join(); } if (window != null) { window.ReleaseHandle(); } }
public SubclassWindowRoot(SubclassWindow child) { _child = child; }