Application window sent behind other windows on closing different thread (C#) Application window sent behind other windows on closing different thread (C#) multithreading multithreading

Application window sent behind other windows on closing different thread (C#)


Try calling .Activate() on your main window when your thread closes.

It's never been active, and thus has low Z-Order, so whatever is higher will naturally be above it. I had to fix this exact scenario in our app.

Don't forget! You may need to marshal the call to the correct thread using an Invoke()!


I've had this happen at times too. Bob's response is the easiest and works for me in the majority of cases. However, there have been some times where I need to use brute force. Do this via interop like this:

[DllImport("user32.dll")]public static extern bool SetForegroundWindow(IntPtr hWnd);


Is the splash screen a Modal dialog?

I have seen this window 'jumping' if you dismiss a Modal dialog twice by setting both DialogResult and calling Hide() or close().

Code like this:

private void button1_Click(object sender, System.EventArgs e){     this.DialogResult = DialogResult.Abort;     this.Hide();}

See this blog entry for all of the cases...