0

This is the background task code and I have used REST client to send the raw notification:

 public sealed class Class2:IBackgroundTask
{
    public void Run(IBackgroundTaskInstance taskInstance)
    {

        var def = taskInstance.GetDeferral();
        RawNotification notification = (RawNotification)taskInstance.TriggerDetails;
        string content = notification.Content;
        ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
        XmlNodeList textElements = toastXml.GetElementsByTagName("text");
        textElements[0].AppendChild(toastXml.CreateTextNode("You have pending items to sync"));
        textElements[1].AppendChild(toastXml.CreateTextNode("Please open the app to sync"));
        ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
        def.Complete();
        // ...

        // Insert code to start one or more asynchronous methods using the "await" keyword.
       // var result = await ExampleMethodAsync();

        // ...

       // _deferral.Complete();
    }
}

Data is sent using REST client as in the following image:

enter image description here

The app is crashing when I send this raw notification. But in the case of sending toast notification, app is showing the notification and the background task is not triggering when the app is closed.

Can anybody please explain to me why the app is crashing and the background task is not triggering?

JSON C11
  • 11,272
  • 7
  • 78
  • 65
  • To identify the crash, you can debug it by using a Try Catch method in your background worker class. The second issue is occurred for me too. :( – asitis Jan 25 '16 at 05:33
  • I didn't write any background worker class.I just wrote the following two lines var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); channel.PushNotificationReceived += channel_PushNotificationReceived; after i sent the message from rest client pushnotification recieved is triggerd.After that app crashed.There is no code in the received event. – srinivas vadlamudi Jan 25 '16 at 06:24
  • I am referring to the Class2 class, you have posted in your question. Put a try catch on channel_PushNotificationReceived method & print the exception on catch block by Debug.Writeline – asitis Jan 25 '16 at 06:31
  • Have you registered your background task in Manifest file? – Saurabh Srivastava Jan 25 '16 at 10:05
  • Yes I have registed the background task but i could not see that task in life cycle events. – srinivas vadlamudi Jan 25 '16 at 10:25

0 Answers0