2016-03-03 44 views
2

我創建了一個BackgroundTask來運行WebService,但是如果我使用附加的調試器運行我的解決方案,一切工作正常,緩慢但很好。但是當我打開appmanager(web界面)開始時,它總是說「無法啓動包[MYPACKAGEID]」。那麼我錯過了什麼?在Windows IoT核心上運行後臺應用程序

下面是完整的項目: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); 
    } 
} 

回答

3

的一點是,有一個與代碼,甚至清單沒有問題,似乎它只是並不意味着運行,而設備處於「當家「模式,您需要將其設置爲satrtup無頭應用程序,然後重新啓動設備。

1

編輯:所有這些問題都與最新版本10.0.14279.1000一起消失,現在GUI終於正常工作。

我一直在爲此付出努力,並且已經取得了巨大的成功,可以幫助某人。所有這些都在Power Shell完成

將設備置於無頭模式,某種程度上我不認爲這是強制性的,但如果沒有它,我就沒有成功。 編輯:這不是這種情況,它現在就應該如此。

https://ms-iot.github.io/content/en-US/win10/HeadlessMode.htm

開始在無頭模式應用程序,並把它添加到啓動應用程序列表 要了解哪些應用程序在啓動列表類型

IotStartup startup

要添加一個無頭的應用程序類型in command

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