private bool IsCorrectThread(HWND hwnd) { int processId; int threadId = NativeMethods.GetWindowThreadProcessId(hwnd, out processId); return (processId == NativeMethods.GetCurrentProcessId() && threadId == NativeMethods.GetCurrentThreadId()); }