[英]Running Background Application on Windows IoT Core
我已经创建了BackgroundTask来运行WebService,但是,如果我在连接调试器的情况下运行解决方案,则一切正常,缓慢但正常。 但是,当我在appmanager(网络界面)中单击“开始”时,它总是显示“无法启动程序包[MYPACKAGEID]”。 那我想念什么?
这是完整的项目: https : //github.com/naice/HomeAutomation.git
public sealed class StartupTask : IBackgroundTask
{
internal static BackgroundTaskDeferral Deferral = null;
public async void Run(IBackgroundTaskInstance taskInstance)
{
//
// TODO: Insert code to perform background work
//
// If you start any asynchronous methods here, prevent the task
// from closing prematurely by using BackgroundTaskDeferral as
// described in http://aka.ms/backgroundtaskdeferral
//
Deferral = taskInstance.GetDeferral();
await ThreadPool.RunAsync(async workItem => {
RestWebServer restWebServer = new RestWebServer(80);
try
{
// initialize webserver
restWebServer.RegisterController<Controller.Home.Home>();
restWebServer.RegisterController<Controller.PhilipsHUE.Main>();
await restWebServer.StartServerAsync();
}
catch (Exception ex)
{
Log.e(ex);
restWebServer.StopServer();
Deferral.Complete();
}
}, WorkItemPriority.High);
}
}
关键是代码甚至清单都没有问题,似乎它并不是要在设备处于“ headed”模式时运行,您需要将其设置为satrtup无头应用程序,然后重新启动设备。
编辑:使用最新版本10.0.14279.1000消除了所有这些问题,现在GUI终于可以正常工作了。
我一直在为此苦苦挣扎,并且这种方法可能会有所帮助,并取得了巨大的成功。 全部在Power Shell中完成
将设备置于无头模式,以某种方式,我认为这不是强制性的,但是没有它我没有成功。 编辑:情况不再如此,它现在应该可以正常工作。
https://ms-iot.github.io/content/en-US/win10/HeadlessMode.htm
以无头模式启动应用程序并将其添加到启动应用程序列表中以查看启动列表中有哪些应用程序
IotStartup startup
在命令中添加无头应用程序类型
IotStartup add headless [Task1]
在命令中添加无头应用程序类型
IotStartup startup headless [Task1]
要找到应用名称,您可以使用以下命令
IotStartup list
要查看您的应用在启动列表中,请输入
IotStartup startup
然后重启您的设备!
我还遇到了一些与从启动中删除应用程序有关的问题,然后尝试通过Visual Studio对其进行调试,在某些情况下,唯一的解决方案是用新映像刷新SD卡。
有关可用命令的完整列表
https://ms-iot.github.io/content/en-US/win10/tools/CommandLineUtils.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.