none
[UWP]Wake up the modern standby machine when data receive over http, RRS feed

All replies

  • Hi,

    I'm not sure about if this could be work. I checked the document, if you wants to use HTTP instead of socket and keep the network communication in the background, ControlChannelTrigger Class is a good choice for you when you create background tasks. But I'm not sure if this will work in modern standby mode, you could make a try about this. 

    For more information, please refer:Network communications in the background

    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.

    Monday, September 9, 2019 3:30 AM
    Moderator
  • Hi Roy,

    I added my app to lockScreen still this line always fails.

                    channel = new ControlChannelTrigger(channelId, serverKeepAliveInterval,
                                               ControlChannelTriggerResourceType.RequestHardwareSlot);

    Error 

    UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) ControlChannelTrigger

    As I mentioned that i am using Curl APIs to revive server initiated http response, so I am planing to open the same connection when machine is about to go in sleep.

    I have few more question

    1. Is adding the app in lock-screen is required, if yes is there any api to directly add the app in it.

    2. Can i use WNS to receive the server initiated messages (Not cloud service to send the message to WNS) 

    3. I am using HTTP2 to receive server message, so which option is better to use with ControlChannelTrigger (HttpClient or IXMLHttpRequest2)


    Tuesday, September 10, 2019 9:50 PM
  • Hi,

    Have you register the background task in your manifest?

    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.

    Wednesday, September 11, 2019 3:58 AM
    Moderator
  • I am using code behind to register it.

    Inside OnLaunched

    foreach (var bgTask in BackgroundTaskRegistration.AllTasks)
                {
                    if (bgTask.Value.Name == taskName)
                    {
                        bgTask.Value.Unregister(true);
                    }
                }
    
                BackgroundTaskBuilder builder = new BackgroundTaskBuilder()
                {
                    Name = taskName,
                    TaskEntryPoint = "Mynamespace.ModernStandby.BackgroundTaskRunner"
    };
    uint serverKeepAliveInterval = 25;
                const string channelId = "channelOne";
    
                const string WebSocketKeepAliveTask = "Mynamespace.ModernStandby.WebSocketKeepAliveTask";
                ControlChannelTrigger channel =null;
                try
                {
                    channel = new ControlChannelTrigger(channelId, serverKeepAliveInterval,
                                               ControlChannelTriggerResourceType.RequestHardwareSlot);
                    LOG.Error("Creating is done.");
                }
                catch (UnauthorizedAccessException exp)
                {
                    LOG.Error("failed "+exp);
                    //return result;
                }
    
    
                // Register the apps background task with the trigger for keepalive.
                var keepAliveBuilder = new BackgroundTaskBuilder();
                keepAliveBuilder.Name = "KeepaliveTaskForChannelOne";
                keepAliveBuilder.TaskEntryPoint = WebSocketKeepAliveTask;
                //keepAliveBuilder.SetTrigger(channel.KeepAliveTrigger);
                keepAliveBuilder.Register();
    
                builder.SetTrigger(channel.PushNotificationTrigger);
                BackgroundTaskRegistration registration = builder.Register();
                registration.Unregister()

    • Edited by pavan tiwari Wednesday, September 11, 2019 4:56 AM
    Wednesday, September 11, 2019 4:55 AM
  • Hi,

    If you wants to register a out-of-process background, you will still need to declare the background task in the manifest. If you wants to create a in-process background, then you won't need to set the TaskEntryPoint property.

    For more information, please refer:Create and register an out-of-process background task and Create and register an in-process background task

    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.

    Wednesday, September 11, 2019 6:42 AM
    Moderator
  • Some how i am able to register my Background Task in my App after changing the project type to Windows runtime component 

          <Extensions>
            <Extension Category="windows.backgroundTasks" Executable="$targetnametoken$.exe" EntryPoint="NameSpace.SampleBackgroundTask">
              <BackgroundTasks>
                <Task Type="controlChannel" />
              </BackgroundTasks>
            </Extension>
            <Extension Category="windows.backgroundTasks" Executable="$targetnametoken$.exe" EntryPoint="NameSpace.ServicingComplete">
              <BackgroundTasks>
                <Task Type="controlChannel"/>
              </BackgroundTasks>
            </Extension>
          </Extensions>

    So as per the doc, this will create BG task in different process, I followed this blog https://docs.microsoft.com/en-us/windows/uwp/launch-resume/debug-a-background-task#trigger-background-tasks-manually-to-debug-background-task-code to see actually my code is getting executed or not. But my break points are not getting hit. So i added a simple file write opertaion just to see my task are getting exeucted or not. It seems like Tasks are not getting  executed.

    Is something else required to make run my tasks?

    How can i define one of the task as KeepAlive task (I don't see an option in manifest). Since I am using ControlChannelTrigger so what should i have to do to actually run my task and keep it alive. 

    WebSocketKeepAlive

    I want to send hart beet to my http server whenever KeepAlive is get called, so how can i create my own class to do so.


    • Edited by pavan tiwari Thursday, September 12, 2019 7:18 AM
    Thursday, September 12, 2019 7:15 AM
  • Hi,

    If you want to create WebSocketKeepAlive background task, please refer ControlChannelTrigger with WebSockets.

    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.

    Thursday, September 12, 2019 10:18 AM
    Moderator
  • Hi Roy,

    I register the task by using the below code.

            <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTasks.BGTask" Executable="$targetnametoken$.exe">
              <BackgroundTasks>
                <Task Type="controlChannel"/>
              </BackgroundTasks>
            </Extension>

    I am facing below compiler  error

    Severity Code Description Project File Line Suppression State
    Error APPX0703 Manifest references file '{My exe}.exe' which is not part of the payload.

    Without 

    Executable="$targetnametoken$.exe"

    App fails during the deployment because of ControlChannel trigger.

    How can i fix this compiler error.

    Sunday, September 15, 2019 1:58 AM
  • Hi,

    Well, you haven't register it yet. Calling BackgroundTaskBuilder.Register() method means you register the background task. But the code in the manifest just declare the background. I created a bank app and add the same code to the manifest file. The app could run without error. Have you tried do it in a blank app?

    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.

    Monday, September 16, 2019 7:20 AM
    Moderator
  • Hi Roy,

    Which App you are taking about? Can you please share the app?

    If you see the code of https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/SocketActivityStreamSocket/cs

    This does not requires a Task Registration again in App.xaml.cs, Manifest registration is sufficient to  run the code. Only diff is i have in my case is that i am using ControllChannelTrigger instead of timer or systemEvent.

     

    Monday, September 16, 2019 7:41 AM
  • A blank app. A new created app. NOT the sample. As I know, the sample implemented the background network communication already. I think it's not possible to trigger this in sleep mode. Sleep mode has many limitations and most of the resources are not available. 

    This https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/modern-standby-wake-sources#universal-windows-platform-uwp-applications-1 tells only notifications will work.

    Monday, September 16, 2019 9:51 AM
  • Hi Roy,

    As per the MS documentation 

    Regardless of the trigger you use, set IsNetworkRequested on your background task to ensure that the network stays up while the background task runs. This tells the background task infrastructure to keep the network up while the task is executing, even if the device has entered Connected Standby mode. If your background task does not use IsNetworkRequested, then your background task will not be able to access the network when in Connected Standby mode (for example, when a phone's screen is turned off)

    To me it seems like BG task can work with connected modern standby, correct? 

    I am struggling to make a working POC on this :(

    3 hours 31 minutes ago