Different Windows Phone (11)

Source: Internet
Author: User
Tags abstract datetime xmlns

Background Task (background tasks) alert (Alarm) and reminders (reminder)

Introduced

Unique Windows Phone 7.5 (SDK 7.1) after the task

Alarm-Alerts

Reminder-Reminders

> Example

1, demo Alarm (in a Time plan pop-up alert information)

Alarmdemo.xaml

<phone:phoneapplicationpage x:class= "Demo.BackgroundTask.AlarmDemo" xmlns= "Http://schemas.microsoft.com/winf X/2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:phone=" Clr-namespace: Microsoft.phone.controls;assembly=microsoft.phone "Xmlns:shell=" clr-namespace:microsoft.phone.shell;assembly= Microsoft.phone "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "fontfamily=" {StaticResource PhoneFontFamilyNormal} "FontSiz E= ' {StaticResource phonefontsizenormal} ' foreground= ' {StaticResource Phoneforegroundbrush} ' SupportedOrientations= "Portrait" orientation= "Portrait" mc:ignorable= "D" d:designheight= "768" d:designwidth= "The Shell:SystemTray.IsVis" 
        ible= "True" > <stackpanel orientation= "Vertical" > <textblock text= "Alarm style"/> 
       <image source= "/backgroundtask/alarm.png"/>    
        <button x:name= "Btnregister" content= "register one minute after the start of Alarm" click= "Btnregister_click"/> <text Block x:name= "lblmsg"/> </StackPanel> </phone:PhoneApplicationPage>

AlarmDemo.xaml.cs

* * Scheduledaction-base class for all scheduled activities, abstract class. Schedulednotification and scheduledtask inherit from this class * schedulednotification-for a time schedule pop-up message, abstract class * * Alarm-a time schedule pop-up alert information, each A program can have up to 50 alert messages at a time. Alarm inherits from Schedulednotification * Name-alarm's name, which is ID * title-The header of the alert, which can only display system defaults and cannot modify the * Content-  Details of the alert * Sound-the address (Uri type) of the alert tone of the alert * begintime-pop-up alert information at this point in time (the system will dispatch all schedulednotification once every minute), which means the system will BeginTime the relevant information within one minute of the specified point in time) * Expirationtime-the expiration time of the alert. When an alert alert is raised, if the user chooses "postpone", the alert information for the plan will continue to pop up after a period of time, but after the point specified in this value, the information for this program will never be popped again * RecurrenceType-the time plan type of the pop-up message. Microsoft.Phone.Scheduler.RecurrenceInterval enumeration: none| daily| weekly| monthly| endofmonth| Yearly * IsEnabled-currently this value is useless * isscheduled-is there an execution plan after this scheduledaction (read-only field) * * Scheduledactionserv Ice-Manage Scheduledaction class * scheduledactionservice.getactions<t> () where t:scheduledaction-Find registered Sch in the system Eduledaction type of Data * Scheduledaction.find (string name)-by nameThe lookup specified Scheduledaction * scheduledaction.remove (string name)-Deletes the specified scheduledaction * Scheduledaction.add by name ( Scheduledaction action)-Register a new scheduledaction * Scheduledaction.replace (scheduledaction action)-Update the specified scheduled 
Action */using System; 
Using System.Collections.Generic; 
Using System.Linq; 
Using System.Net; 
Using System.Windows; 
Using System.Windows.Controls; 
Using System.Windows.Documents; 
Using System.Windows.Input; 
Using System.Windows.Media; 
Using System.Windows.Media.Animation; 
Using System.Windows.Shapes; 
   
Using Microsoft.Phone.Controls; 
   
Using Microsoft.Phone.Scheduler; namespace Demo.backgroundtask {public partial class Alarmdemo:phoneapplicationpage {public alarmde 
   
            Mo () {InitializeComponent (); This. 
        Loaded + = new Routedeventhandler (alarmdemo_loaded); } void Alarmdemo_loaded (object sender, RoutedEventArgs e) {ShowregisTeredalarm (); }//Display Alarm private void Showregisteredalarm () {//Ienumerable<sch in the program 
            edulednotification> notifications = scheduledactionservice.getactions<schedulednotification> (); 
            ienumerable<alarm> alarms = scheduledactionservice.getactions<alarm> (); Lblmsg.text = "The registered Alarm in the program has the name:" + String. Join (",", alarms.) Select (P => p.name). 
        ToList ()); } private void Btnregister_click (object sender, RoutedEventArgs e) {//lookup program specified in Alarm, 
            If not, instantiate a Alarm Alarm = Scheduledactionservice.find ("Alarm") as Alarm; 
                   
            if (alarm = = null) alarm = new Alarm ("alarm"); Alarm. title = "Alarm title"; The Title property of Alarm cannot modify Alarm. 
            Content = "Alarm content"; Alarm. 
            Sound = new Uri ("/assets/supermario.mp3", urikind.relative); Alarm. BeginTime = DatetIme. 
            Now.addminutes (1); Alarm. 
            Expirationtime = DateTime.Now.AddDays (1); Alarm. 
   
            RecurrenceType = recurrenceinterval.daily;; If there is no specified Alarm in the program, ADD, otherwise Replace if (Scheduledactionservice.find ("Alarm") = null) Sche 
            Duledactionservice.add (alarm); 
   
            else Scheduledactionservice.replace (alarm);             
        Showregisteredalarm (); } 
    } 
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.