首页 > 解决方案 > App or Code to Suspend Resume UWP app without Visual Studio

问题描述

My question is similar to How to make UWP app to suspend and resume state, but I need an application that I can give to my QA team so that they can more easily invoke Suspend and Resume in my app.

Since Visual Studio has a "LifeCycle Events" toolbar that lets you suspend and resume your App, I figure that there must be an app that ships with Visual Studio that does this. However, perusing through the Visual Studio files, I was not able to find such an executable.

Does anyone know of a stand-alone application (installed with Visual Studio or not) that can suspend or resume a windows store app?

If not, does anyone have sample code that can suspend or resume an arbitrary UWP app? I understand that there are some C++ libraries for building a debugger, but I'm not a C++ programmer. If there's a C# way to do this, please post some code. If it must be a C++ application, please post a complete example that is easy to build.

标签: c#c++debugginguwpsuspend

解决方案


UWP 提供用于暂停和恢复应用的专用 API: StartSuspendAsync StartResumeAsync

例如,您可以如何暂停 FeedbackHub 应用程序:

var diag = await AppDiagnosticInfo.RequestInfoForPackageAsync("Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe");
if (diag.Count > 0)
{
    var resourceGroups = diag[0].GetResourceGroups();
    if (resourceGroups.Count > 0)
    {
        await resourceGroups[0].StartSuspendAsync();
    }
}

请注意,您需要声明“appDiagnostics”功能才能调用这些 API:

<Package
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp rescap">
  ...

  <Capabilities>
    <rescap:Capability Name="appDiagnostics" />
  </Capabilities>
</Package>

推荐阅读