I am assuming I need to use pinvoke but I am not sure which function calls are needed.
Scenario: a legacy application will be running, I will have Handle for that ap
This has proved to be extremely reliable. The ShowWindowAsync function is specifically designed for windows created by a different thread. The SW_SHOWDEFAULT makes sure the window is restored prior to showing, then activating.
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool ShowWindowAsync(IntPtr windowHandle, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetForegroundWindow(IntPtr windowHandle);
Then making the calls:
ShowWindowAsync(windowHandle, SW_SHOWDEFAULT);
ShowWindowAsync(windowHandle, SW_SHOW);
SetForegroundWindow(windowHandle);