简体   繁体   中英

UWP How to notify of Process's termination?

For UWP, I am looking for something similar to .NET System.Diagnostics.Process capability for notifying about Process's termination like:

process.EnableRaisingEvents = true;
process.Exited += Process_Exited;

...

private static void Process_Exited(object sender, EventArgs e)
{
    var process = (Process)sender;
    // Do some stuff
}

At the moment, I'm able to work out Windows.System.Diagnostics.ProcessDiagnosticInfo object which represent a 'the Process' I need. The problem is, that Windows.System.Diagnostics.ProcessDiagnosticInfo type doesn't provide mechanism (event, etc) which could tell me 'Hey, this process has been ended'.

Does any UWP's API support it ?

Unfortunately it seems no UWP API is available for this so far. ProcessDiagnosticInfo provides basic info about a process and there doesn't seem to be any way to further manipulate it (eg wire up events). Furthermore, even though UWP now supports .NET Standard, the classes related to System.Diagnostics.Process mostly throw PlatformNotSupported exception, presumably for security reasons.

The only option I can see now is to query the list of running processes repeatedly and check if the process you are watching is still listed or not. Of course, is not the best solution, as you won't get an immediate notification, so if you want faster feedback, you must execute the check more often.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM