[UWP]如何使用ThreadPoolTimer.CreatePeriodicTimer立即开始工作 [英] [UWP]How to start a job immediately with ThreadPoolTimer.CreatePeriodicTimer

查看:105
本文介绍了[UWP]如何使用ThreadPoolTimer.CreatePeriodicTimer立即开始工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在的作用就像等待>工作>等待......

如何像工作一样工作>等等>工作......?

https://docs.microsoft.com/en-us/windows/uwp/threading-async/create-a-periodic-work-item

https://docs.microsoft.com/en-us/windows/uwp/threading-async/create-a-periodic-work-item

推荐答案

你好Kevin Jing1,

Hello Kevin Jing1,

可能,这是不可能的立即(同步)进行第一次打勾。但是,通过手动调用TimerElapsedHandler进行第一次"工作",可以模拟这样的序列。请尝试以下代码。

Probably, it's impossible to make the first tick immediately (synchronously). But it's possible to simulate such a sequence by just calling TimerElapsedHandler manually for the first "work". Try the code below anyway.

{
    TimerElapsedHandler handler = (ThreadPoolTimer timer) =>
    {
        Debug.WriteLine("Tick:\t" + DateTime.Now.ToString());
    };

    Debug.WriteLine("Start:\t" + DateTime.Now.ToString());

    var theTimer = ThreadPoolTimer.CreatePeriodicTimer(handler, TimeSpan.FromSeconds(3));

    handler(theTimer); // Make the first tick manually. 

    // Subsequent ticks are to be made by the ThreadPoolTimer.
}


这篇关于[UWP]如何使用ThreadPoolTimer.CreatePeriodicTimer立即开始工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆