sorosh_sabz
sorosh_sabz

Reputation: 3003

How to show message dialog on Background task in windows phone 10 UWP

I have the background task, and I want to show a message dialog in this background task in some situations like below.

public sealed class TestTask : IBackgroundTask
{
   public async void Run(IBackgroundTaskInstance taskInstance)
   {
      dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;  // -> Crash this line
   }
}

As you can see from Problems with show dialog on Background task in windows phone 8.1 when I trying to access the UI thread from background task I want to use CoreDispatcher. But when I want to use CoreDispatcher in UWP background task, CoreWindows.GetForCurrentThread().Dispatcher is null in constructor and run method, and I get null pointer exception with below message

Object reference not set to an instance of an object

Is something has changed in windows phone 10 (UWP) from Windows phone 8.1?

Upvotes: 0

Views: 894

Answers (1)

Barptad
Barptad

Reputation: 174

Just to clear up this question, based on the comments here are your options.

  1. If you want to have a background task which needs to show information with additional actions to take upon completion use interactive toasts.
  2. If this user interaction action is critical use modals in the actual app and look at in process background tasks, however I see no reason why the need for background task at that point.

If none of the above options suits you it's time to reconsider your current scenario...

Upvotes: 1

Related Questions