![](/img/trans.png)
[英]handle user tapped event on area of screen for windows phone 8.1 app
[英]Event at app shutdown Windows Phone 8.1
我正在使用相機為Windows Phone創建我的第一個應用程序。 在關閉時,我想調用一個dispose方法從MediaCapture object
釋放資源。 但是我找不到一個在應用程序關閉時觸發的事件。
有誰知道我如何在關機時處置該對象? 現在,當關閉應用程序時,原因導致手機凍結。
在您的app.xaml.cs中,您通常會獲得此類
public sealed partial class App : Application
在創建項目時,內部已經有兩種有趣的方法
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// some code here
// will run when app launch
}
還有這個
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
// some code here
}
因此,如您在解釋功能的摘要中所讀,當用戶掛起應用程序時會調用該函數,但是您不知道該應用程序將終止還是稍后恢復,因此我認為您沒有辦法。
因此,我建議將您的資源放置在OnSuspending函數中
那是針對Windows Phone 8.1和Windows 8.1 Metro風格的應用程序
如果要在WPF項目中執行此操作,實際上
OnExit(ExitEventArgs e)
請參閱此處的Msdn文檔(僅適用於WPF)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.