How to display a clock with the current time in a Windows Core IoT app?

一笑奈何 提交于 2019-12-02 03:18:35

If your app is running headless, you will have to set data to a display device (LCD, LEDs, etc.). With a headed app, you will use a XAML page to display the clock. You can use a timer to get notified every time span occurs.

Timer declaration

ThreadPoolTimer _clockTimer = null;

Timer initialization

_clockTimer = ThreadPoolTimer.CreatePeriodicTimer(_clockTimer_Tick, TimeSpan.FromMilliseconds(1000));

Timer tick event

private void _clockTimer_Tick(ThreadPoolTimer timer)
{
    //Update your display. Use a dispatcher if needed
}

ThreadPoolTimer reference documentation

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.system.threading.threadpooltimer.aspx

Keep in mind that a Raspberry Pi does not have a battery to save the current time. Your board will have to sync through the Internet to update its date/time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!