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:
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?