c# - UWP Toast Notification debugging in Visual Studio - no toast displaying, "Returned with error code 0x0" -


i have background task supposed open toast message, à la: toastnotificationmanager.createtoastnotifier().show(toast);. code executes fine, no errors thrown, nothing hangs -- also, no toast message appears.

i checked event viewer logs, , this:

an instance of background task entry point bg.toastbackgroundtask running user [me] in session [sesh] returned error code 0x0.

i have looked on see error code might mean found nothing.

here's code:

public sealed class toastbackgroundtask : ibackgroundtask {     private backgroundtaskdeferral _deferral;      public async void run(ibackgroundtaskinstance taskinstance)     {         var canceltoken = new system.threading.cancellationtokensource();         taskinstance.canceled += (s, e) =>             {                 canceltoken.cancel();                 canceltoken.dispose();             };          taskinstance.task.completed += task_completed;          _deferral = taskinstance.getdeferral();         try         {             await sendnotificationasync();         }         { _deferral.complete(); }      }      public static async void register()     {         var isregistered = backgroundtaskregistration.alltasks.values.any(x => x.name == nameof(toastbackgroundtask));         if (isregistered) return;          var accessstatus = await backgroundexecutionmanager.requestaccessasync();         if (accessstatus == backgroundaccessstatus.deniedbyuser || accessstatus == backgroundaccessstatus.deniedbysystempolicy) return;          var builder = new backgroundtaskbuilder         {             name = nameof(toastbackgroundtask),             taskentrypoint = $"{nameof(mynamespace)}.{nameof(bg)}.{nameof(toastbackgroundtask)}"         };          builder.settrigger(new timetrigger(120, false));          var task = builder.register();     }      private static void task_completed(backgroundtaskregistration sender, backgroundtaskcompletedeventargs args)     {         try         {             args.checkresult();         }         catch (exception ex)         {             debug.writeline(ex.message);         }     }      private task sendnotificationasync()     {         var service = new toastservice();         service.createtoast(new toastviewmodel { title = "title", text = "text", imagepath = "", id = 3 });         return task.completedtask;     }         } 

if run checkresult() on completed task, no errors thrown. argh! know (a) event viewer log error means, or (b) why toast isn't showing up?

here's toast code in case helps:

public class toastservice {     public void createtoast(toastviewmodel model)     {         var visual = new toastvisual()         {             bindinggeneric = new toastbindinggeneric()             {                 children =                 {                     new adaptivetext() { text = model.title },                     new adaptivetext() { text = model.text }                 },                 attribution = new toastgenericattributiontext() { text = "via me" }             }         };          var tcontent = new toastcontent()         {             visual = visual,             activationtype = toastactivationtype.background,             scenario = toastscenario.reminder         };          var toast = new toastnotification(tcontent.getxml())         {             expirationtime = datetime.now.adddays(model.expiration)         };         toast.failed += (o, args) => {             var message = args.errorcode;         };          toastnotificationmanager.createtoastnotifier().show(toast);     } } 

does know (a) event viewer log error means, or (b) why toast isn't showing up?

the above event log showed on side information level, not error level. reason toast isn't showing should setting expirationtime property toastnotification. property for:

gets or sets time after toast notification should not displayed.

so if model.expiration equals 0, toast not show now. ensure expiration time later should work.

var toast = new toastnotification(tcontentxml) {    expirationtime = datetime.now.adddays(1) }; 

otherwise code snippet can work on side. if still have issues, can provide minimal reproduced project let have testing.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -