Reputation: 595
Programmatically, how can I determine the 3 categories in Windows 10
Just like Task Manager?
i.e. I need some C# code which I can determine a list of Apps vs. a list of background process. Checking executionState in Win32_process doesn't work. It's always null.
Thanks!
Upvotes: 2
Views: 4211
Reputation: 595
The original problem:
I have a different take regarding the solution:
Some UWP apps has the main window title. Checking main window title is not enough to say the app is running or not.
UWP apps in suspend state will still return the title (see the red rectangle)
So in order to detect the suspend state, we need to cover
{code}
static void byProcess()
{
Process[] processes = Process.GetProcesses();
List<string> suspendedAppsWhichHasTitle = new List<string>();
foreach (var proc in processes)
{
// if it has main window title
if (!string.IsNullOrEmpty(proc.MainWindowTitle))
{
// the app may be in suspend state
foreach (ProcessThread pT in proc.Threads)
{
ThreadState ts = pT.ThreadState;
if (ts == ThreadState.Running)
{
suspendedAppsWhichHasTitle.Add(proc.MainWindowTitle);
}
}
}
}
foreach(string app in suspendedAppsWhichHasTitle)
{
Console.WriteLine(app);
}
if (suspendedAppsWhichHasTitle.Count == 0)
{
Console.WriteLine("No visible app is running!");
}
Console.Read();
}
}
Upvotes: 1