最好安排在C#中的任务的方式 [英] Best way to schedule tasks in C#

查看:102
本文介绍了最好安排在C#中的任务的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发,需要能够调度各种异步任务在不同的时间C#程序。我需要一个解决方案,激活每一秒钟检查任务的执行,并吃掉了尽可能少的资源成为可能。这也需要很好地扩展到了大量的任务。哪一项是更好地使用,或者是有什么?

I'm developing a C# program that needs to be able to schedule a variety of asynchronous tasks at different times. I need a solution that activates every second to check for tasks to execute, and eats up as few resources as possible. It also needs to scale well to a large number of tasks. Which of these is better to use, or is there any ?

1)使用与1秒的总时间System.Timers.Timer的目的在于,触发执行任务的事件,或者

1) Using a System.Timers.Timer object with a 1 second elapsed time to trigger an event that executes tasks, or

2)使用休眠1秒一个单独的线程,然后执行任务时就醒来,或

2) Using a separate thread that sleeps for 1 second and then executes tasks when it wakes up, or

3)完全是另一回事。

3) Something else entirely.

推荐答案

System.Threading.Timer 是极其轻便。你可以为每个任务一个单独的计时器,这样计时器来,由于任务的时候应该执行。

System.Threading.Timer is extremely lightweight. You could create a separate timer for each task so that the timer comes due when the task is supposed to execute.

在内部,我认为,该系统会跟踪哪些定时器是由于旁边,因此只需要监控一个定时器,在任何给定时间(<一href="http://stackoverflow.com/questions/31581/how-scalable-is-system-threading-timer">source/similar问题)。

Internally, I believe that the system will keep track of what timer is due next so it only has to monitor one timer at any given time (source/similar question).

这篇关于最好安排在C#中的任务的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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