locked
[UWP]ControlChannelTrigger Background Task RRS feed

  • Question

  • Hey guys,

    I'm trying to run a ControlChannelTrigger in an in-process background task (on xbox), and I'm getting an 0x80070005 error. I can run the ControlChannelTrigger as an out of process task, but this is behaving weird on restarts on the app on the xbox, so I'd like to move it in-process.

    Can this even be done, as creating a new ControlChannelTrigger throws the UnauthorizedAccessException.

    Thoughts?

    This code replicates the issue in a completely new UWP app.

    • Need to add the following reference to compile: Windows Desktop Extensions for the UWP


    namespace App1
    {
        public sealed partial class MainPage
        {
    
            public MainPage()
            {
                InitializeComponent();
    
                Loaded += MainPage_Loaded;
            }
    
            private static async void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                var task = new BackgroundTaskBuilder
                {
                    Name = "MessageWebSocket Trigger"
                };
    
                var trigger = new ControlChannelTrigger(Guid.NewGuid().ToString(), 45);
    
                var socket = new MessageWebSocket();
                socket.Control.MessageType = SocketMessageType.Utf8;
    
                trigger.UsingTransport(socket);
    
                task.SetTrigger(trigger.PushNotificationTrigger);
    
                await socket.ConnectAsync(new Uri("wss://echo.websocket.org"));
    
                trigger.WaitForPushEnabled();
    
                await BackgroundExecutionManager.RequestAccessAsync();
    
                if (BackgroundExecutionManager.GetAccessStatus() == BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
                {
                    task.Register();
                }
            }
        }
    }

    Thursday, September 6, 2018 11:00 AM

Answers

  • Hi,

    I found it similar case that might answer your question on StackOverflow here. He said that "The registered background task cannot be an in-process task and must be registered as an out-of-process task." in his answer.  So it seems to be better using out-of-process background.

    Could you please tell me more about the weird behavior of the trigger. Maybe we could try to figure it out.

     

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by AdamPengelly Monday, September 10, 2018 10:20 AM
    Friday, September 7, 2018 10:05 AM

All replies

  • Hi,

    I found it similar case that might answer your question on StackOverflow here. He said that "The registered background task cannot be an in-process task and must be registered as an out-of-process task." in his answer.  So it seems to be better using out-of-process background.

    Could you please tell me more about the weird behavior of the trigger. Maybe we could try to figure it out.

     

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by AdamPengelly Monday, September 10, 2018 10:20 AM
    Friday, September 7, 2018 10:05 AM
  • Roy, thanks so much for your reply.

    I was afraid it was the case the it had to be out of process.

    When run out of process, by task runs fun. However, when I close the app, and try to run it again. It hangs. If I then close it, and try again, it works. So, it apparently can't recover the task and delete it (which is what I'm trying to do when I start the app).


    Monday, September 10, 2018 9:21 AM
  • Forget all the above!

    I was doing a check for when to progress to the splash screen, and I was checking like this:

    ApplicationExecutionState[] reloadStates =
    {
       ApplicationExecutionState.ClosedByUser,
       ApplicationExecutionState.Terminated
    };
    
    if (reloadStates.Contains(e.PreviousExecutionState))
    {
       ... Do whatever to initialise app, then navigate to frame
    }
    else 
    {
       ...navigate to frame.
    }

    Even though the app was shut down, the e.PreviousExecutionState was "NotRunning" instead of "ClosedByUser" or "Terminated"

    I heart UWP

    Monday, September 10, 2018 10:20 AM