DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Windows Phone: Reminder in Depth

Sumit Dutta user avatar by
Sumit Dutta
·
Jul. 08, 12 · Interview
Like (0)
Save
Tweet
Share
4.43K Views

Join the DZone community and get the full member experience.

Join For Free

In this article I will discuss how to create Reminder in Windows Phone. I will also deep dive in few other aspects of Reminder feature in Windows Phone.

Let's create a simple reminder. I will use timepicker control to set the reminder and activate it. Timepicker is available in Silverlight Windows Phone Toolkit

Download Silverlight Windows Phone Toolkit

Step 1: Create a silverlight for Windows Phone project.

Step 2: Add reference of Microsoft.Phone.Controls.Toolkit.dll
Step 3: Add namespace of Microsoft.Phone.Controls.Toolkit in MainPage.xaml.

xmlns:toolkit="clr- namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

Step 4: Add timepicker control inside grid of MainPage.xaml. It has timePicker_ValueChanged which will trigger on change of time.

 

<toolkit:TimePicker Header="Start Time" x:Name="timePicker" Margin="0,250,0,0" Width="450" HorizontalAlignment="Left" ValueChanged="timePicker_ValueChanged"/>

Step 5: Add Microsoft.Phone.Scheduler directive.

 

using Microsoft.Phone.Scheduler;

Step 6: In the code behind of MainPage.xaml add timePicker_ValueChanged method.

 

 

private void timePicker_ValueChanged(object sender, EventArgs args)
{
   string reminderName = Guid.NewGuid().ToString();
   Reminder reminder = new Reminder(reminderName);
   reminder.Title = "My Reminder";
   DateTime date = DateTime.Today;
   DateTime beginTime = date + ((DateTime)timePicker.Value).TimeOfDay;
   reminder.BeginTime = beginTime;
   
   //reminder.ExpirationTime = date.AddHours(20);
   
   reminder.RecurrenceType = RecurrenceInterval.Daily;
   ScheduledActionService.Add(reminder);
}

We can use Guid to generate random name of reminder. Begintime of reminder can be set using DateTime.Today and the value selected in timepicker.

We can set RecurrenceType by using RecurrenceInterval enum.

The options of enum are:

 

None = 0 : No recurrence. The notification is launched once at the time specified by Microsoft.Phone.Scheduler.ScheduledAction.BeginTime


Daily = 1: Daily recurrence

Weekly = 2: Weekly recurrence

Monthly = 3: Monthly recurrence

EndOfMonth = 4: Recurring at the end of each month

Yearly = 5: Yearly recurrence

Note: If BeginTime is exceeded by more than 4 hours then Reminder won't be launched.

Step 7: Now wrap the above code which loops for 50 times like below.

private void timePicker_ValueChanged(object sender, EventArgs args)
{
   for (int i = 0; i < 50; i++)
   {
      string reminderName = Guid.NewGuid().ToString();
      Reminder reminder = new Reminder(reminderName);
      reminder.Title = "My Reminder";

      DateTime date = DateTime.Today;
      DateTime beginTime = date + ((DateTime)timePicker.Value).TimeOfDay;
      reminder.BeginTime = beginTime;

      //reminder.ExpirationTime = date.AddHours(20);
      reminder.RecurrenceType = RecurrenceInterval.Daily;
      ScheduledActionService.Add(reminder);
   }
}

Step 8: Uninstall this app from emulator or device if you have already run it.Now run the program again with 50 loops and set the reminder. It will work fine. Now run the emulator again, you will notice that you will get InvalidOperationException was unhandled as shown below.

Windows Phone - Reminder BNS Error

BNS Error: The maximum number of ScheduledActions of this type have already been added.

Step 9: Now uninstall the app with 50 loop and increase the loop count to 51 and run the app again.

You will get the same above error again.

So, conclusion is there is limit of 50 active reminders per application in Windows Phone. Once you add Reminder to ScheduledActionService, it remains in application until you remove it.

As per above the Reminder will stop working once you reach threshold of 50.

To make reminder work N number of times, the previous reminder(s) needs to be removed from ScheduledAction before setting new reminder.

Step 10: Add System.IO.IsolatedStorage directive.

using System.IO.IsolatedStorage;

Step 11: Store the reminder name in the IsolatedStorage. Remove the reminder name from the ScheduledActionSerive before adding new one.

 

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
string strReminder;
if (settings.TryGetValue<string>("Reminder", out strReminder))
{
   ScheduledActionService.Remove(strReminder);
}

string reminderName = Guid.NewGuid().ToString();
settings["Reminder"] = reminderName;

Now one can set reminder N number of times.

This ends the article of Reminder in Windows Phone.

Windows Phone

Published at DZone with permission of Sumit Dutta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Upgrade Guide To Spring Data Elasticsearch 5.0
  • Mr. Over, the Engineer [Comic]
  • Fraud Detection With Apache Kafka, KSQL, and Apache Flink
  • Memory Debugging: A Deep Level of Insight

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: