public void Run(IBackgroundTaskInstance taskInstance) { // Ensure our background task remains running taskDeferral = taskInstance.GetDeferral(); // Example: Create a timer-initiated ThreadPool task RobotStateTimer = ThreadPoolTimer.CreatePeriodicTimer(PopulateRobotStateData, TimeSpan.FromSeconds(TaskIntervalSeconds)); Bot = new HoloLensRobot(); // Start the server server = new RobotHttpServer(port, Bot); var asyncAction = ThreadPool.RunAsync((w) => { server.StartServer(); }); // Task cancellation handler, release our deferral there taskInstance.Canceled += OnCanceled; }