I created a c# winform application. It opens a new window (without borders, like a popup if this matters) which should always stay on top of the main form. The window is opened by a thread:
Task.Run(() => ...
in the constructor of the new form I tried to add :
this.TopMost = true;
Sometimes the window goes in the background of the main form. And sometimes i can't even open it from the taskbar. I click on it and nothing happens.
- There are no other applications with a window open
- I tried it on Windows 7 and 10 (different pc's)
- I tried to call following method from form.load (which to be honest I have no idea what it does exactly) :
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
public static UInt32 SWP_NOSIZE = 0x0001;
public static UInt32 SWP_NOMOVE = 0x0002;
public static UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
Nothing helped. Does someone have an idea?