2014-02-19 65 views
1

在Windows Phone 8中,当我按下开始按钮时,我应该得到Application_DeactivatedApplication_Closing事件。但是当我在这些事件中设置断点时,断点不会命中。为什么Application_ClosingApplication_Deactivated没有被调用?为什么应用程序没有收到应用程序关闭事件?

Please refer

Occurs when an application stops being the foreground application.

的App.xaml

<Application 
    x:Class="ContineousLocationTracking.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"> 

    <!--Application Resources--> 
    <Application.Resources> 
     <local:LocalizedStrings xmlns:local="clr-namespace:ContineousLocationTracking" x:Key="LocalizedStrings"/> 
    </Application.Resources> 

    <Application.ApplicationLifetimeObjects> 
     <!--Required object that handles lifetime events for the application--> 
     <shell:PhoneApplicationService 
      Launching="Application_Launching" Closing="Application_Closing" 
      Activated="Application_Activated" Deactivated="Application_Deactivated" 
      RunningInBackground="PhoneApplicationService_RunningInBackground" 
      /> 
    </Application.ApplicationLifetimeObjects> 

</Application> 
+0

这些方法中是否有任何代码?因为如果它们是空的,编译器可以删除它们。 – xmashallax

+0

你是如何设置这些事件的? – CathalMF

+0

@xmashallax不,我在事件中有代码 –

回答

1

这就是你投入Deactivation enent应该叫。我建议阅读Application lifecycle at MSDN。有很多信息,所以我不会在这里发布。

您可以确定在Deactivation事件中设置断点(根据注释中的解释)。

但是当您按下开始按钮时,不会调用关闭事件。

更多有用的链接:


如果您有问题检查你的App.xaml如果使用这些事件:

<Application.ApplicationLifetimeObjects> 
    <!--Required object that handles lifetime events for the application--> 
    <shell:PhoneApplicationService 
     Launching="Application_Launching" Closing="Application_Closing" 
     Activated="Application_Activated" Deactivated="Application_Deactivated"/> 
</Application.ApplicationLifetimeObjects> 

,它不会被调用(瞬间)如果您的应用程序设置为运行背景(位置跟踪)。它可以在specific circumstances中调用。

+0

'停用事件也没有被调用。 –

+0

@pranitkothari看我的编辑并检查你的App.xaml。 – Romasz

+0

做过同样的事情,但bp没有命中。 –

相关问题