Windows 8 Metro/Immersive App - Force Terminate

偶尔善良 提交于 2019-12-25 06:18:08

问题


I'm working on porting an app from iOS to WinRT/8 Metro/8 Immersive/Whatever the current name is.

On iOS, we have the ability to set Application does not run in background to YES to cause the app to actually quit whenever the user leaves the app.

I would like to figure out how to replicate this behavior in WinRT.

  1. Yes, I understand that this is abnormal behavior.
  2. Yes, I have thought this through.
  3. Yes, I have an extremely good reason for doing this.

I'm assuming that during the userLeavingApp event, I would just call Application.Current.Exit(), but I can't seem to find the userLeavingApp event. I thought about using OnSuspending (Handles Me.Suspending) in App.xaml.vb, but that doesn't seem to be called quickly enough for me.

Is there a .NET equivalent of viewWillDisappear or something?

Any ideas? This is an important security characteristic of my app, and I'd hate to have such difficulty in an entire platform due to such a small issue.

Thanks!


回答1:


I'm not actually seeing Application.Current.Exit() working in OnSuspending; although as you mention the suspending isn't happening fast enough for you (which is by design). Throwing an exception there didn't work for me either.

There is Window.VisibilityChanged and if I issue Exit/exception there, it does shutdown the app when another app takes over. That said, VisibilityChanged will fire under other circumstances too so not sure if you could cover all the scenarios or rely on them not changing. See here for a bit more context.

To echo @Filip, whose response just popped in, it's highly unlikely you'll pass certification. An Exit() call is tantamount to an exception.




回答2:


I don't think your app will pass certification if you call Application.Current.Exit(). If you are really confident this is what you want - I guess it is worth a shot to try. You could though simply unload anything that uses memory/CPU when you exit.



来源:https://stackoverflow.com/questions/14777131/windows-8-metro-immersive-app-force-terminate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!