0

Following this example (http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202967(v=vs.105).aspx) I have enabled my Windows Phone 8 app for push notifications. I can receive notifications and the callback method PushChannel_ShellToastNotificationReceived is called. From the example, this method opens a message box with the notification contents.

Can I therefore assume that it is safe to execute UI related operations from the thread the callback is executed in? I see that the message box is wrapped in Dispatcher.BeginInvoke(() =>, however I have no idea what thread this will be executed in, and what objects I should use from this thread.

Eran
  • 387,369
  • 54
  • 702
  • 768
user826955
  • 3,137
  • 2
  • 30
  • 71

1 Answers1

1

PushChannel_ShellToastNotificationReceived is always called by the OS when a push notification is received while your app is running so it will execute on a non-UI thread.

Any UI related code that needs to be executed must be wrapped inside Dispatcher.BeginInvoke(Action a) otherwise you'll get an UnauthorizedAccessException exception.

Alaa Masoud
  • 7,085
  • 3
  • 39
  • 57
  • Okay thanks for the info. So `Dispatcher.BeginInvoke(Action a)` magically executes the code in the UI thread and thats it, problem solved? :) – user826955 Sep 06 '13 at 06:20