简体   繁体   English

如何在应用程序终止然后使用 Visual Studio 以 xamarin 形式启动时进行调试

[英]How to debug when the app is terminated and then launched in xamarin forms using Visual Studio

I am developing a Xamarin Forms app using Visual studio.我正在使用 Visual Studio 开发 Xamarin Forms 应用程序。

I want to test this scenario:我想测试这个场景:

  1. I open an app我打开一个应用
  2. Do some operations做一些操作
  3. Terminate the app and launch the application终止应用程序并启动应用程序
  4. Now I want to hit a break point in Visual Studio现在我想在 Visual Studio 中打一个断点

How to achieve this?如何实现这一目标? Mainly I would like to test these events - Suspended, Shutdown and Resume.我主要想测试这些事件 - 暂停、关闭和恢复。

Can someone please help me out?有人可以帮我吗?

It has to do with Xamarin.它与Xamarin 有关。 Forms Lifecycle Methods : Put your breakpoints in following methods inside the App.xaml.cs class: 表单生命周期方法:将断点放在App.xaml.cs类中的以下方法中:

OnStart - Called when the application starts. OnStart - 在应用程序启动时调用。

OnSleep - Called each time the application goes to the background. OnSleep - 每次应用程序进入后台时调用。

OnResume - Called when the application is resumed, after being sent to the background. OnResume - 在应用程序被发送到后台后恢复时调用。

Note that there is no method for application termination.请注意,没有终止应用程序的方法。 Under normal circumstances (ie. not a crash) application termination will happen from the OnSleep state, without any additional notifications to your code.在正常情况下(即不是崩溃),应用程序将从 OnSleep 状态终止,不会向您的代码发送任何额外的通知。

To observe when these methods are called, implement a WriteLine call in each (as shown below) and test on each platform.要观察这些方法何时被调用,请在每个方法中实现一个 WriteLine 调用(如下所示)并在每个平台上进行测试。

protected override void OnStart()
{
    Debug.WriteLine ("OnStart");
}
protected override void OnSleep()
{
    Debug.WriteLine ("OnSleep");
}
protected override void OnResume()
{
    Debug.WriteLine ("OnResume");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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