none
[Desktop Converter] [C#] Usage of ApplicationTrigger BackgroundTasks

    Question

  • Hi,

    I'm currently working on a project with a Win32 app which is converted with the Desktop Bridge / Centennial. I found this sample which is able to run a BackgroundTask with MaintenanceTrigger. However, I would like to be able to run a BackgroundTask via ApplicationTrigger. This does not work with this sample when replacing the MaintenanceTrigger with an ApplicationTrigger. (Error message: GetAwaiter is not defined for ApplicationTrigger.RequestAsync)

    I also found this description that tells which assemblies need to be referenced to support some UWP functionality: Enhance your desktop application for Windows 10

    I was able to register BackgroundTasks with this instruction - however, they never get executed. The ApplicationTrigger has an error, too - "IAsyncOperationWithProgress is defined in a non-referenced assembly. Add a reference to the Assembly 'Windows..." - however, the Windows assembly is in conflict with one of the assemblies mentioned in "Enhance your desktop application for Windows 10" (Windows.Foundation.UniversalApiContract).

    So here is my question: How do I need to setup my project to support BackgroundTasks triggered via ApplicationTrigger?

    I appreciate any help,

    Manuel Kurtz


    Manuel Kurtz

    • Moved by CoolDadTx Monday, November 26, 2018 2:59 PM UWA related
    Monday, November 26, 2018 8:31 AM

All replies

  • Hi,

    >> How do I need to setup my project to support BackgroundTasks triggered via ApplicationTrigger?

    To use the ApplicationTrigger to activate a background task from within your app, there are some steps as below:

    1, Create an application trigger.

    2, Call RequestAccessAsync to determine the level of background activity the user allows because the user may have disabled background activity for your app.

    3, Register the background task by calling your background task registration function.

    4, Trigger the background task by calling ApplicationTrigger.RequestAsync.

    5, Use BackgroundExecutionManager.RequestAccessAsync to determine if the user has decided that your app’s background activity should be limited.

    For more detailed information for the code sample, please refer to the following document:

    Trigger a background task fromwithin your app.

    >> I'm currently working on a project with a Win32 app which is converted with the Desktop Bridge / Centennial.

    How did you implement the background task in your Win32 app?

    The following document tells how to use background tasks from a Win32 console app.

    DesktopBridgeToUWP-Samples / BackgroundTasksSample.

    Hope this helps.

    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.

    Tuesday, November 27, 2018 9:30 AM
    Moderator
  • Hi Roy,

    I've uploaded a small sample app where I managed to execute a BackgroundTask via MaintenanceTrigger. It also contains an ApplicationTrigger-BackgroundTask - however, this one is not executed when clicking on the appropriate button.

    You can download my sample here: Centennial Sample

    The Centennial Sample contains four projects. One is the UWP-, one the Win32- and one the BackgroundTasks-Project. The last project is for packaging to use UWP features in the Win32-Application. To use the UWP-features, a compiler-flag "DesktopUWP" must be set.

    I was not able to use the ApplicationTrigger.RequestAsync method when only referencing the Windows.winmd, therefore I added the references to System.Runtime.* and Windows.Foundation.FoundationContract.winmd as described in Enhance your desktop application for Windows 10.

    It would be great if you could check my code for issues and find out why the ApplicationTrigger does not execute the backgroundtask when requested.

    Kind regards,

    Manuel


    Manuel Kurtz

    Friday, November 30, 2018 5:29 AM
  • Hi ,

    Sorry for the late reply.

    I downloaded the project and in my test, the ApplicationTrigger can be triggered when I set a breakpoint in the ToastSender(BackgroundTask) class, so could you please provide more detailed information such as some reproducing steps?

    Also please provide the version of your OS.

    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.

    Tuesday, December 4, 2018 2:46 AM
    Moderator
  • Hi,

    I am using Visual Studio Enterprise 2017. My OS version is Windows 10 Professional, Version 1803 (Build 17134.407).

    When I debug the Centennial.Win32Packaging project, a breakpoint in the ToastSender(BackgroundTask) is not hit when clicking on the appropriate button for triggering the BackgroundTask.

    Kind regards, 

    Manuel


    Manuel Kurtz

    Wednesday, December 5, 2018 6:11 AM
  • Hi,

    I reproduced your problem. I'm asking other engineers about this.

    There will be some time delay. Appreciate your patience in advance.

    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, December 6, 2018 8:51 AM
    Moderator