c# - 在 Windows IoT Core 上运行后台应用程序

标签 c# win-universal-app windowsiot

我已经创建了一个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/

相关文章:

dns - 解决 SoftAP 上的 minwinpc.local

c# - 在大型代码库中查找字符串 == 运算符的用法

c# - 将矩形排列成螺旋状

react-native - 如何开始使用React Native编写UWP应用?

javascript - WebView 不会触发 YouTube 中的导航事件

windows - DEP0001 : Unexpected Error: -1988945906 while deploying Windows UWP app to phone

c# - 如何在没有 Visual Studio 的情况下部署已编译的应用程序?

c# - 如何在 ASP.NET Core 中设置启动路由

c# - 如何从 WinRT 中的 TypeInfo 获取类型?