如何在启动时运行 Windows App SDK 打包的 C# 应用程序?

huangapple go评论104阅读模式
英文:

How to run Windows App SDK packaged C# app at startup?

问题

我想要让我的打包的C#应用在登录时启动。在这篇帖子的指导下,我配置了Package.appxmanifest并将相关的代码添加到我的应用程序。然而,当用户登录时,启动画面出现,但应用程序无法启动。

帖子提到了一点:

如果您的应用启用了启动激活,您应该通过覆盖OnActivated方法在您的App类中处理这种情况。

然而,WASDK应用程序没有"OnActivated"方法。我猜问题出在这里,我想知道如何正确配置我的代码来解决这个问题。

感谢任何帮助。

英文:

I want to run my packaged c# app to start at log-in. Under the guidance of this post, I configured Package.appxmanifest and added relevant code to my app. However, when users log in, the splash screen appears but then the application fails to launch.

The post mentions one thing:

> If your app is enabled for startup activation, you should handle this
> case in your App class by overriding the OnActivated method.

However, WASDK app doesn't have an OnActivated method. I guess the problem lies here and I wonder how to correctly configure my code to fix this issue.

Appreciate any help.

答案1

得分: 1

已解决。
根据此博客,我们应该以以下形式编写package.appxmanifest

  1. <Extensions>
  2. <uap5:Extension
  3. Category="windows.startupTask"
  4. Executable="SingleInstancedError.exe"
  5. EntryPoint="SingleInstancedError.App">
  6. <uap5:StartupTask
  7. TaskId="SingleInstancedErrorId"
  8. Enabled="false"
  9. DisplayName="SingleInstancedError startup" />
  10. </uap5:Extension>
  11. </Extensions>

但是,为了使其适用于Windows App SDK,必须删除这两行:

  1. Executable="SingleInstancedError.exe"
  2. EntryPoint="SingleInstancedError.App"

这样清单看起来像这样:

  1. <Extensions>
  2. <uap5:Extension
  3. Category="windows.startupTask">
  4. <uap5:StartupTask
  5. TaskId="SingleInstancedErrorId"
  6. Enabled="false"
  7. DisplayName="SingleInstancedError startup" />
  8. </uap5:Extension>
  9. </Extensions>

然后应用程序会在启动时正常运行。

英文:

Resolved.
According to this blog, we are supposed to write package.appxmanifest in this form:

  1. &lt;Extensions&gt;
  2. &lt;uap5:Extension
  3. Category=&quot;windows.startupTask&quot;
  4. Executable=&quot;SingleInstancedError.exe&quot;
  5. EntryPoint=&quot;SingleInstancedError.App&quot;&gt;
  6. &lt;uap5:StartupTask
  7. TaskId=&quot;SingleInstancedErrorId&quot;
  8. Enabled=&quot;false&quot;
  9. DisplayName=&quot;SingleInstancedError startup&quot; /&gt;
  10. &lt;/uap5:Extension&gt;
  11. &lt;/Extensions&gt;

However, to make it work for Windows App SDK, these two lines must be removed:

  1. Executable=&quot;SingleInstancedError.exe&quot;
  2. EntryPoint=&quot;SingleInstancedError.App&quot;

So that the manifest looks like this:

  1. &lt;Extensions&gt;
  2. &lt;uap5:Extension
  3. Category=&quot;windows.startupTask&quot;&gt;
  4. &lt;uap5:StartupTask
  5. TaskId=&quot;SingleInstancedErrorId&quot;
  6. Enabled=&quot;false&quot;
  7. DisplayName=&quot;SingleInstancedError startup&quot; /&gt;
  8. &lt;/uap5:Extension&gt;
  9. &lt;/Extensions&gt;

And the app runs normally at startup.

huangapple
  • 本文由 发表于 2023年3月4日 01:18:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定