-1

I know Windows Store Apps are executed in isolated mode (a sandbox). Hence I start an App (e.g. Microsoft Photos) by using IApplicationActivationManager.ActivateForFile, the image provided gets displayed and the return value of the function gives me the process Id (e.g. 6544 for a process named ‘ApplicationFrameHost’ and a main window title of ‘Photos’. But when I register a handler to the .Exited() event of the according process I won’t get informed when I close the App (unlike to a Win32/64 application like notepad.exe).

Unpleasantly furthermore I receive the same Process Id for the next image to be displayed as well – both images are held by the same process now. And all images displayed subsequently return the very same process Id as well... and my .Exited-Handler is still not called, neither in case I close only one of now several running Photo-Apps nor after finally I have closed all of them.

Since I could not yield notification about the process with my image was closed I thought of looking up if it is still on display. I investigated all propertied of Process including the ProcessThreadCollection and ProcessStartInfo but found nothing to identify my displayed images. And even when I investigate the MainWindowsTitles by looping through the open windows (with User32.EnumWindows() or WindowsInterop.GetRootWindowsOfProcess(p.Id) this does not give me more then fife times “Photos” for fife displayed images – alas without the filenames of the images displayed!

Any hint to get around that would be greatly appreciated!

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51

1 Answers1

0

You can use AppDiagnosticInfoWatcher to monitor the state of an app and get notifications when it changes:

https://learn.microsoft.com/en-us/uwp/api/windows.system.appdiagnosticinfowatcher

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51