David
David

Reputation: 1709

Multiple scheduled toasts on windows phone

I'm writing one application (windows phone 8) which has to show multiple toasts at a given time. To do so I use one "ScheduledTaskAgent" project.

protected override void OnInvoke(Microsoft.Phone.Scheduler.ScheduledTask task)
{

    ShellToast toast = new ShellToast();
    toast.Content = task.Description;
    toast.Show();

    NotifyComplete();

    ScheduledActionService.Remove(task.Name);
}

And to add a new task/toast I do :

 private static void AddToSchedule(DateTime date, string id, Toast toast)
{
    PeriodicTask periodicTask = new PeriodicTask(toast.Id);

    periodicTask.Description = toast.Title;
    ScheduledActionService.Add(periodicTask);
    var showIn = date - DateTime.Now;
    ScheduledActionService.LaunchForTest(toast.Id, showIn);
}

If I add one task/toast it is working. But if I want to add more I have one System.InvalidOperationException.

(Which means : BNS Error: The maximum number of ScheduledActions of this type have already been added.).

How may I change this to be able to add toasts to one task.

Updated :

I changed my AddToSchedule() and now it's working.

 private static void AddToSchedule(DateTime date, string id, Toast toast)
{
    Reminder reminder = new Reminder(toast.Id);
    reminder.Title = toast.Title;
    reminder.Content = toast.Title;
    reminder.BeginTime = DateTime.Now.AddMinutes(1);
    reminder.ExpirationTime = reminder.BeginTime.AddSeconds(5.0);
    reminder.RecurrenceType = RecurrenceInterval.None;
    ScheduledActionService.Add(reminder);
}

Is there a way to use toast instead of reminder ?

Upvotes: 0

Views: 517

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65556

If you want a reminder to show to the user at a specific time you have a few options:

If you want to raise the notification from the device you can use an Alert or Reminder.

If you want to show a Toast notification you'll have to send this from a remote source using a Push Notification.

Upvotes: 1

Related Questions