How do I Force suspension of Metro app - c#

How do we force an app to Suspend (NOT shutdown, just suspend) and then force-resume it ourselves when we are NOT using visual studio/debugging?

When running under Visual Studio 2012, you can enable the Debug Location on the debugger toolbar. This will allow you to select one of the three operations, "suspend", "resume", and "suspend and shutdown".
[edited]
Sorry, just noticed that you are asking for non VS solution. You can suspend your app by dragging the app down. Move your cursor to the top of the page until you see a hand. Click and hold it and pull down to suspend your app. It takes a few seconds before the app actually enter suspend mode. If you want to do things sooner, you can use visibility change to toggle certain action first, like saving critical stuff.

Related

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.
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.
When I add ShutdownMode="OnExplicitShutdown" to my app.xaml, I get these errors in my Error List:
The member "ShutdownMode" is not recognized or is not accessible.
The property 'ShutdownMode' was not found in type 'Application'.
Also I notice that there is no StartupUri specified, nor can I add one (same errors as above.)
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.
The Application class is of type Windows.UI.Xaml.Application.
If I pause VS after closing the app, it takes me to this (generated) code:
#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?
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.
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.
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 :)
Truly stopping the process is easy, just click the Red Button on the VS toolbar.

Visual Studio Profiling: Start/Stop from code

Is there a possibility to start/stop the visual studio (Professional 2012+) profiler from code? I know you can start it paused, but to start the profiling, you have to click on a button in the visual studio.
In my case, I would like to start it when clicking on a button in my application, which switches to a new view, and automatically stop it when the UI was loaded. I would like to see why there is such a large delay until the UI shows up.
I've not used it before, but it seems you're looking for Profiling API.
DataCollection.StartProfile and DataCollection.StopProfile looks like the methods you're interested in.

Does debugger prevent suspension?

When my windows store app goes to the background it still keeps running.
According to the documentation of the App.Suspend event the app should suspend after a few seconds when in background.
I tried running the app on a simulator and on a real device, both with a debugger attached.
Is the debugger preventing the app from suspension? Or am I mistaken that the app suspends after a few seconds when it is in the background?
Yes, the debugger prevents suspension. In Visual Studio, however, you can force suspend, resume, and suspend+terminate. There's a dropdown on the toolbar for this purpose when you're running the app, which lets you trigger background tasks for debugging as well.

WinRT How to Test and simulate Suspension States [duplicate]

How can you tell when a windows 8 Metro app gets put in the background? The suspended state doesn't activate. I have a break point on. It only hits if I close the app.
I am using a webcam and since no apps can run in the background I need to save my work when it's put in the background.
The windows phone it was application deactivated.
any help would be nice.
Apps do not normally get suspended when in the debugger. However, you can force a suspend when debugging by:
Enabling the Debug Location toolbar (red arrow in image below).
Then press the Suspend button (blue arrow).
The suspending event should fire when the application is no longer active, namely, when another application is brought to the front. Presuming you're using C#/XAML, the app.xaml.cs file already has the Suspending event wired up. In HTML5/JavaScript it's checkpoint and you'll see it in default.js.

WPF Application stalls/freezes after first interaction, like button click

I'm currently experiencing a problem in WPF. The UI loads fine, but whenever the first user interaction is made, such as a button click, the application seems to stall, or example if I had two buttons that display a MessageBox, the first click will wait for a few seconds then show the MessageBox, but any subsequent interaction is instantaneous and responsive.
Has anyone else experienced this? And if so, is there any solution?
Thanks
I had the same problem. Every time I called the first interaction from a Button or ICommand the UI would freeze for like half a second.
I tracked down the issue with the hint of the author to start application directly from the folder. This solved the issue, but I also wanted to know why this happens and thought about what the difference is between direct execution and debugging.
So I figured out that IntelliTrace caused the freeze, which was still enabled since I activated it once for debugging an ADO.NET application. After disabling, the UI Freeze is gone. To disable it go to Debug -> IntelliTrace -> Open IntelliTrace Settings -> untick "Enable IntelliTrace".
Thanks for reporting this performance issue. We have looked into it and tracked it down. We are looking into fixing this in a future release. Below are steps to work around this issue. Once the work around is applied there is no need to disable ‘Gesture’ events or IntelliTrace.
Open up a cmd window under Admin account
cd /d "%programfiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\Remote Debugger\x64"
%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install /NoDependencies /ExeConfig:.\msvsmon.exe Microsoft.VisualStudio.vil.host.dll
If you are using a VM you might want to first save a snapshot before applying the work around. Let us know if you run into any other issues. Thanks.
Azeem Khan

Categories

Resources