我已经创建了一个BackgroundTask来运行WebService,但是如果我在附加调试器的情况下运行我的解决方案,一切都会正常运行,虽然缓慢,但很好。但是当我在应用程序管理器(网络界面)中点击开始时,它总是显示“无法启动包 [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);
}
}
最佳答案
重点是代码甚至 list 都没有问题,似乎它只是不适合在设备处于“有头”模式时运行,您需要将其设置为 satrtup headless 应用程序,然后重新启动设备。
关于c# - 在 Windows IoT Core 上运行后台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35781614/