關閉后,我的Windows應用商店應用程序仍在調試模式下運行

[英]My Windows Store app is still running in debug mode after I close it


I'm writing my first Windows Store app (windows 8.1) and I notice that when I run it in debug mode, and I close the app (by clicking the x in the top right, or by dragging from the top of the screen to the bottom), it is still running in Visual Studio. My first question is, is this a problem? It seems like it's a problem.

我正在編寫我的第一個Windows應用商店應用程序(Windows 8.1),我注意到當我在調試模式下運行它時,我關閉應用程序(通過單擊右上角的x,或者從屏幕頂部拖動到它仍然在Visual Studio中運行。)我的第一個問題是,這是一個問題嗎?這似乎是一個問題。

I started from a template, I'm not doing anything with threads, and there is only one page (MainPage.xaml) at the moment. I have looked at questions which seem similar, in particular this one: WPF App Doesn't Shut Down When Closing Main Window but I am unable to get their suggestions to work.

我從一個模板開始,我沒有對線程做任何事情,目前只有一個頁面(MainPage.xaml)。我已經查看了類似的問題,特別是這一個:WPF應用程序在關閉主窗口時沒有關閉,但我無法得到他們的建議。

When I add ShutdownMode="OnExplicitShutdown" to my app.xaml, I get these errors in my Error List:

當我將ShutdownMode =“OnExplicitShutdown”添加到我的app.xaml時,我在錯誤列表中收到以下錯誤:

  • The member "ShutdownMode" is not recognized or is not accessible.
  • 成員“ShutdownMode”無法識別或無法訪問。
  • The property 'ShutdownMode' was not found in type 'Application'.
  • 在“應用程序”類型中找不到屬性“ShutdownMode”。

Also I notice that there is no StartupUri specified, nor can I add one (same errors as above.)

另外我注意到沒有指定StartupUri,也不能添加一個(與上面相同的錯誤。)

The other suggestion was to override OnClosed in MainWindow.xaml.cs and close the application there. I have no MainWindow.xaml.cs; I have MainPage.xaml.cs instead, and it does not have an OnClosed.

另一個建議是在MainWindow.xaml.cs中覆蓋OnClosed並在那里關閉應用程序。我沒有MainWindow.xaml.cs;我改為使用MainPage.xaml.cs,它沒有OnClosed。

The Application class is of type Windows.UI.Xaml.Application.

Application類的類型為Windows.UI.Xaml.Application。

If I pause VS after closing the app, it takes me to this (generated) code:

如果我在關閉應用程序后暫停VS,則會轉到此(生成的)代碼:

#if !DISABLE_XAML_GENERATED_MAIN
public static class Program
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    static void Main(string[] args)
    {
        global::Windows.UI.Xaml.Application.Start((p) => new App()); //<==here
    }
}
#endif

Can anyone tell me what's going on?

誰能告訴我發生了什么事?

1 个解决方案

#1


4  

This is entirely normal, the debugger tells you what is really going on. All Modern UI apps work this way. Just check it out with Task Manager, Details tab. Observe how dismissing the window doesn't terminate the process, it just suspends it.

這完全正常,調試器會告訴您實際發生了什么。所有Modern UI應用程序都以這種方式工作只需使用任務管理器,詳細信息選項卡進行檢查。觀察解雇窗口如何不終止進程,它只是暫停它。

You don't just have a modern UI, you have modern operating system behavior as well. A user doesn't have enough information available to judge if terminating a process is actually useful. If the machine has plenty of resources then there isn't any point. Better to keep the process running so that when the user starts it again, it instantly wakes up. Which is nice, users like that.

您不僅擁有現代UI,還擁有現代操作系統行為。用戶沒有足夠的信息來判斷終止進程是否真的有用。如果機器有足夠的資源,那么沒有任何意義。最好保持進程運行,以便當用戶再次啟動時,它會立即喚醒。哪個好,用戶喜歡。

Conversely, if the OS requires resources for another process and not enough are available than it will automatically terminate a process without the user's assistance. The life-cycle for Modern UI apps supports this. Nothing particularly revolutionary btw, mobile operating systems like Android do this as well. Also the way I use my desktop apps these days, I just leave them running. Until I run out of taskbar space, cleanup then. Annoying :)

相反,如果操作系統需要另一個進程的資源而且沒有足夠的資源,那么它將在沒有用戶幫助的情況下自動終止進程。 Modern UI應用程序的生命周期支持這一點。沒有什么特別具有革命性的btw,像Android這樣的移動操作系統也可以做到這一點。這些天我使用桌面應用程序的方式,我只是讓它們運行。直到我用完任務欄空間,然后清理。討厭:)

Truly stopping the process is easy, just click the Red Button on the VS toolbar.

真正停止該過程很簡單,只需單擊VS工具欄上的紅色按鈕即可。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/02/07/72f8fc11fd86d9538f45a5799e320206.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com