[UWP]应用程序在最小化并最大化应用程序时崩溃。 [英] [UWP]App crashes when minimised and maximised the app.

查看:285
本文介绍了[UWP]应用程序在最小化并最大化应用程序时崩溃。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在最小化并打开时崩溃。这在读取csv文件(100万条记录)时造成了一些时间来处理/读取数据。

My app crashes when minimizing and open it.This caused while reading csv file (100 thousands records) it cause some time to process/read the data.

下面我附加了App.xaml.cs。

Below I had attached the App.xaml.cs.

  public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
        }

        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
             rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }

        /// <summary>
        /// Invoked when Navigation to a certain page fails
        /// </summary>
        /// <param name="sender">The Frame which failed navigation</param>
        /// <param name="e">Details about the navigation failure</param>
        void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
        }

        /// <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)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Save application state and stop any background activity
            deferral.Complete();
        }

如何解决此问题?有谁能帮我找出解决方案?

How to resolve this issue?Can anyone help me to figure out the solution?

提前致谢快速回复 

Thanks in advance for quick reply 

dinez

推荐答案

Hi Dinez,

Hi Dinez,

应用程序崩溃,因为它在最小化时暂停。

App crashes because it is suspended when minimized.

您可以阻止UWP应用程序在停用时暂停或者最小化。

You can prevent your UWP app from suspending when it is deactivated or minimized.

要实现这一目标,您应该使用
扩展执行API

To achive this you should use the Extended Execution API.

您可以通过以下某种方式使用此API:

You can use this API in some way like:

var extendedExecutionSession = new ExtendedExecutionSession();
extendedExecutionSession.Reason = ExtendedExecutionReason.Unspecified;
var extendedExecutionResult = await extendedExecutionSession.RequestExtensionAsync();
if (extendedExecutionResult != ExtendedExecutionResult.Allowed)
{
//extended execution session revoked
     extendedExecutionSession.Dispose();
     extendedExecutionSession = null;
}


您可以在一个方法中插入此代码,该方法是您的UWP应用程序的入口点并根据您选择的方式处理启动(OnLaunched或OnActivated) )。

You can insert this code in a method that is the entry point of your UWP app and handles the launch, depending of the way which you have chosen (OnLaunched or OnActivated).


这篇关于[UWP]应用程序在最小化并最大化应用程序时崩溃。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆