如何在 Windows 8.1 上向使用者發送通知?

如何在 Windows 8.1 上向使用者發送通知?

我想在電腦工作期間休息一下。

如何在 Windows 8.1 上每 50 分鐘向使用者發送一次通知?

答案1

試試這樣的事情:

//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);
}

和:

//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
        }
}

相關內容