locked
[UWP]How to run a task in background on a page navigation RRS feed

  • Question

  • In my winRt universal project,I have a menu page(for example).

    When I click a menu option it will navigate to another page.At this time I need to call a API (long task) for update the menu setting in DB.

    The issue that I faced is :

    the page navigation is slow because it occurs after the API call.So I need to call that API in background without affecting navigation.

    can anyone help me?


    dinez


    • Edited by Krunal Parekh Friday, December 4, 2015 6:42 AM subject
    Thursday, December 3, 2015 12:46 PM

Answers

  • I would put the info you want to save in a shared property.  Before you navigate put the data in the shared property.  When we get to the new page save the data in the shared property in the onnavigated to event
    • Proposed as answer by Krunal Parekh Tuesday, December 8, 2015 8:20 AM
    • Marked as answer by Krunal Parekh Thursday, December 17, 2015 2:25 AM
    Thursday, December 3, 2015 3:25 PM
  • Hello Dinez,

    You can not manually run the background task but you need to use a trigger for it. once the condition is met the trigger actives and run the background task.

    Please see: Windows.ApplicationModel.Background namespace (lists the available triggers)

    But I think in your case just doing async call would solve the problem.as described by @Ken  Tucker 

    Make your method static async and it should not interfere with the navigation.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Krunal Parekh Tuesday, December 8, 2015 8:20 AM
    • Marked as answer by Krunal Parekh Thursday, December 17, 2015 2:26 AM
    Friday, December 4, 2015 6:24 AM

All replies

  • I would put the info you want to save in a shared property.  Before you navigate put the data in the shared property.  When we get to the new page save the data in the shared property in the onnavigated to event
    • Proposed as answer by Krunal Parekh Tuesday, December 8, 2015 8:20 AM
    • Marked as answer by Krunal Parekh Thursday, December 17, 2015 2:25 AM
    Thursday, December 3, 2015 3:25 PM
  • Hello Dinez,

    You can not manually run the background task but you need to use a trigger for it. once the condition is met the trigger actives and run the background task.

    Please see: Windows.ApplicationModel.Background namespace (lists the available triggers)

    But I think in your case just doing async call would solve the problem.as described by @Ken  Tucker 

    Make your method static async and it should not interfere with the navigation.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Krunal Parekh Tuesday, December 8, 2015 8:20 AM
    • Marked as answer by Krunal Parekh Thursday, December 17, 2015 2:26 AM
    Friday, December 4, 2015 6:24 AM