0

I want to make breaks during PC work.

How to sent notification to user every 50 min on windows 8.1?

1
  • 2
    Use the task scheduler
    – DavidPostill
    Dec 6, 2015 at 19:04

1 Answer 1

0

Try something like this:

//Sending a toast notification
public static async void SendNotificationAsync()
{
        NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string. with full access>", "<hub name>");
        var toast = @"<toast><visual><binding template=""Stop using your PC!""><text id=""1"">50 Minutes are over. Have a break.</text></binding></visual></toast>";
        await hub.SendWindowsNativeNotificationAsync(toast);
}

And:

//goes somewhere into your initialization part; initializes the timer and sets some variables
private Timer timer;
private int time;

timer = new Timer(){Interval = 1000*60};
timer.Tick += new EventHandler(timer_Tick);

-

//Timer class which is executed every minute?!
void timer_Tick(object sender, EventArgs e)
{
    //if time (your countdown) is not null it's reduced by one again and again till it's null
    if(time--<=0)
    {
          //if the left time is finally null the timer is stopped and the toast notification fired off
          timer.Stop();
          SendNotificationAsync();
        }
        else
        {
          //actually nothing
        }
}
6
  • how does use this script? can you explain?
    – catch23
    Dec 7, 2015 at 8:29
  • I'd add some comments.
    – Gamerboy59
    Dec 7, 2015 at 12:30
  • can you add your comments?
    – catch23
    Dec 15, 2015 at 11:54
  • They're already added. ^^
    – Gamerboy59
    Dec 16, 2015 at 19:00
  • how to use this script? can you explain more about this script usage?
    – catch23
    Dec 17, 2015 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .