2

我已经创建了一个 BackgroundTask 来运行一个 WebService,但是如果我运行我的解决方案并附加了调试器,那么一切正常,缓慢,但是很好。但是当我在appmanager(webinterface)中点击开始时,它总是说“无法启动包[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);
    }
}
4

2 回答 2

3

关键是代码甚至清单都没有问题,似乎它只是不打算在设备处于“有头”模式时运行,您需要将其设置为 satrtup 无头应用程序,然后重新启动设备.

于 2016-03-04T16:29:31.220 回答
1

编辑:所有这些问题都在最新版本 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

于 2016-03-10T07:12:08.210 回答