Test this:
var openWindowProcesses = System.Diagnostics.Process.GetProcesses()
.Where(p => p.MainWindowHandle != IntPtr.Zero && p.ProcessName != "explorer");
The openWindowProcesses
should contains all open application which they have an active main window.
I put p.ProcessName != "explorer"
in the where expression because the explorer is the main process of the Desktop and it should never be closed.
To watching execution of the processes you can use ManagementEventWatcher
class. See this please.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…