Windows 7 - start process foreground

179 Views Asked by At

my problem occures on Windows 7.

Background:

I have two applications:

a) MainApp - software which should always run in foreground, maximized (with no taskbar)

b) Watchdog - software which monitors MainApp if it runs properly and starts new MainApp instance if one is closed.

Problem:

Everything works well. But I noticed that sometimes on Windows 7 MainApp starts minimized - it shows icon on taskbar, WindowState is "Maximized" (checked in logs), but Form is not visible until I restore it from taskbar. Problem not occuring on Windows 10 (other not checked).

Reproduce steps I managed to reproduce this problem by:

a) Run Watchdog + MainApp

b) Click Win+D (minimize all windows)

c) Close MainApp (with mouse from taskbar)

d) Watchdog is restarting MainApp minimized <= PROBLEM!!

Show me the code

Watchdog starts MainApp by simply executing:

var info = new ProcessStartInfo();
info.FileName = clientExePath;
info.UseShellExecute = false;
Process.Start(info);

Expected behaviour

MainApp starts in front of all other windows, visible.

Does anyone know how to handle this problem?

EDIT 1

I found out that calling extern method from Shell32.dll

void ToggleDesktop();

restores all windows. But I don't know how to check whether all windows minimized (to fire this method). Additionaly it restores all opened windows, so it is not sure that MainApp form will be the most-first one.

0

There are 0 best solutions below