简体   繁体   English

创建C#Windows后台应用程序服务

[英]Creating a C# Windows background app service

I wonder how I can "set the background task to AppService". 我想知道如何“将后台任务设置为AppService”。

I tried to create a Windows 10 application for Cortana and I follow these steps: https://msdn.microsoft.com/en-us/library/dn974228.aspx 我尝试为Cortana创建Windows 10应用程序,请按照以下步骤操作: https : //msdn.microsoft.com/en-us/library/dn974228.aspx

I somehow can't figure out what I need to do here, because I don't have the appxmanifest file: 我不知道在这里我需要做什么,因为我没有appxmanifest文件:

In Visual Studio, open your app and declare the background task as an AppService in the app manifest. 在Visual Studio中,打开您的应用程序,然后在应用程序清单中将后台任务声明为AppService。

I know that sounds weird, but I could really not seek out. 我知道这听起来很奇怪,但是我真的找不到。 Thanks for help. 感谢帮助。

在此处输入图片说明

  1. Double click Package.appxmanifest 双击Package.appxmanifest
  2. -> Declarations ->声明
  3. Select Background Tasks 选择Background Tasks
  4. Click Add 点击添加
  5. Click the More Info link for more information 单击More Info链接以获取更多信息

在此处输入图片说明

From your screenshot, it looks like you skipped a step, and only created a solution with a Runtime Component project in it, but the background task is intended to be added to an existing universal windows app. 从屏幕快照中,您似乎跳过了一个步骤,只创建了一个包含“运行时组件”项目的解决方案,但后台任务旨在添加到现有的通用Windows应用程序中。

If you're looking to create an app that also implements a background task that can run inside Cortana, you'll want to do the following: 如果您要创建一个应用程序,该应用程序还实现了可以在Cortana内部运行的后台任务,则需要执行以下操作:

  1. Create a new blank app of the Universal Windows type ( eg, c# -> Windows -> Universal -> Blank app from the new project window). 创建一个通用Windows类型的新空白应用程序(例如,从新项目窗口中选择c#-> Windows->通用->空白应用程序)。
  2. Inside that solution, go to file -> New -> Project and create a new Windows Runtime Component (you've already performed that step above) 在该解决方案中,转到文件->新建->项目,然后创建一个新的Windows运行时组件(您已经在上面执行了该步骤)
  3. From the blank app project, you'll install your Voice Command Definition (VCD) file (as per the documentation linked in your question), update the package manifest, etc. 从空白的应用程序项目中,您将安装语音命令定义(VCD)文件(根据问题中链接的文档),更新程序包清单等。
  4. From the Windows Runtime Component project, you'll implement the code that will run in Cortana's background task when invoked by a voice command. 在Windows运行时组件项目中,您将实现在语音命令调用时将在Cortana的后台任务中运行的代码。
  5. From the blank app project, add a reference to the runtime component to ensure that both projects are deployed when you run the app from VS/install it. 从空白的应用程序项目中,添加对运行时组件的引用,以确保在从VS运行/安装应用程序时都部署了两个项目。

I'll agree that the steps in the documentation aren't completely clear, they mention it as a prerequisite but it's not explicit enough. 我同意文档中的步骤尚不完全清楚,他们将其作为先决条件,但还不够明确。 I'll pass that along to the MSDN documentation team. 我会将其传递给MSDN文档团队。 The reason you need two separate projects (for C# and C++/CX projects anyway) is because you'll still need an existing app to install the VCD file into Cortana, and it can be launched by Cortana depending on some of the outcomes of the background task. 您需要两个单独的项目(无论如何对于C#和C ++ / CX项目)的原因是,您仍然需要一个现有的应用程序才能将VCD文件安装到Cortana中,Cortana可以根据VCD文件的某些结果来启动它。后台任务。

The documentation that the MSDN article you link is based on the sample code here: Cortana Voice Command in Microsoft's sample github repository which should help demonstrate how to connect the projects together. 您链接的MSDN文章的文档基于此处的示例代码:Microsoft的示例github存储库中的Cortana Voice Command ,该文档应有助于演示如何将项目连接在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM