线程池-定期调用线程 [英] Thread Pool - invoke thread periodically

查看:63
本文介绍了线程池-定期调用线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些任务应该每隔一段时间执行一次.我希望在线程池中的线程中处理此任务.我是否应该每隔一段时间就有一些线程来调用该任务,然后让其余时间进入睡眠状态,还是有一个更优雅的环境 解决方案

您可以使用:

System.Threading.Timer

System.Timers.Timer

两个都在使用线程池

 

您也可以使用

ThreadPool.RegisterWaitForSingleObject(AlwaysBlockingObject,......,false);

..使用注册的WaitForSingle对象的常规超时.它也使用线程池线程.


I have some task that should be done every some period of time. I want this task to be handled in a thread from Thread Pool. Should I have some thread to invoke the task every some period of time and the rest of time to sleep or is there a more elegant way to do it using .Net Thread Pool?

解决方案

You can use:

System.Threading.Timer

System.Timers.Timer

Both are using the Threadpool

 

You can also use

ThreadPool.RegisterWaitForSingleObject(AlwaysBlockingObject, ...... , false);

.. to use a regular timeout of a registered WaitForSingle object. Its using a threadpool thread, too.


这篇关于线程池-定期调用线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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