运行 Windows IoT Core 上的后台应用程序
Running Background Application on Windows IoT Core
我已经为 运行 一个 WebService 创建了一个 BackgroundTask,但是如果我 运行 我的解决方案附加了调试器,一切正常,虽然缓慢,但很好。但是当我在应用程序管理器(网络界面)中点击开始时,它总是显示 "failed to start package [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);
}
}
关键是代码和manifest都没有问题,好像只是设备处于"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
我已经为 运行 一个 WebService 创建了一个 BackgroundTask,但是如果我 运行 我的解决方案附加了调试器,一切正常,虽然缓慢,但很好。但是当我在应用程序管理器(网络界面)中点击开始时,它总是显示 "failed to start package [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);
}
}
关键是代码和manifest都没有问题,好像只是设备处于"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