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

前端 未结 1 402
余生分开走
余生分开走 2021-01-22 02:03

I am trying to create an Windows 10 IoT app running headless on a Raspberry Pi 2. Everything is set up correctly and I am able to debug my from Visual Studio using the Raspberry

相关标签:
1条回答
  • 2021-01-22 02:23

    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.

    0 讨论(0)
提交回复
热议问题