如何安排执行事件? [英] How do I schedule events for execution ?

查看:66
本文介绍了如何安排执行事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我想做大量的预定任务(比方说80)。每个任务都可以在每个工作日的某个时间运行
。例如,上午10点和每个星期一下午5点每天下午5点,等等。


我想问一下检查和运行

预定活动。


在我脑海中出现的第一个(也许是愚蠢的)是使用

计时器和蜱"事件,检查是否有任务需要

被解雇。


然而这种方法似乎很尴尬,它会浪费很多

资源。我想如果我继续忙于我的程序检查每个刻度

是否有任务要运行,我只会降低整个程序的性能(必须做的)其他几个繁重的任务。


任何人都可以如此友善地建议我这个问题的最佳方法是什么?有没有办法在没有使用时间的情况下直接在

点燃事件,或者更多地使用它?




非常感谢您提前。


-Pam

Hi guys!

I want to do a large number of scheduled task (say 80). Each task can
be run at a certain time every given weekday. For instance at 10am and
5pm on each monday, etc.

I would like to ask what is the best approach to check and run the
scheduled events.

The first (perhaps silly) thing that come up in my mind is to use a
Timer and on the"Tick" event to check if there are task that need to be
fired.

However this approach seems awkward and it would waste a lot of
resources. I think that if I keep busy my program checking at each tick
whether there are task to run, I would only degrade the whole
performance of the program (which must do several other heavy tasks).

Could anyone be so kind as to suggest me what is the best approach to
this problem. Is there a way to have the events fired directly at the
given times without using the times stuff, or using it more
appropriately ?

Thank you very much in advance.

-Pam

推荐答案

Pam,


为什么其中一个计时器会占用大量资源?


我会在你的情况下使用的第一件事(鉴于此任务在

一个程序,否则它将是调度程序)


如果它是windowsform只是windowsform计时器。


只是我的想法,


Cor
Pam,

Why does one of the timers use a lot of resources?

The first thing I would use in your situation (given that the task are in
one program otherwise it would be the scheduler)

And if it is a windowsform just the windowsform timer.

Just my thought,

Cor


- 要执行的所有任务都存储在一个程序中。

-这是一个Windows应用程序。

- 预定任务的数量可以非常高。


天真的方法我首先想到的是定义一个Timer。然后在

" Tick"处理程序放置检查所有任务的代码并决定是否有需要执行的任务。


我在考虑放置此检查循环(这可能很长)在Tick事件中
(并因此每次执行几次$ / b $ b秒),这将是一个尴尬的方法,在这个意义上我会保持

忙于一个线程只做一个循环,大部分时间都没有好处

然后执行任何计划任务。


从这个意义上来说,我觉得浪费资源。


1.最好的办法是什么?


2.当我开始新的尝试时,我必须创建一个新的线程来运行它。

或者它是由Tick处理程序自动分配给新的吗?


-Pam


Cor Ligthert [MVP] ha scritto:
-All task to be executed are stored in one program.
-It''s a windows application.
-The number of scheduled task can ve very high.

The naive approach I first thought of is to define a Timer. Then in the
"Tick" handler to place the code that examines all task and decides if
there are task which need to be executed.

I was thinking that placing this check loop (which could be quite long)
in the Tick event (and therefore executing it several times per
second), would be an awkward approach, in the sense that I would keep
busy a thread just doing a loop which most the times is not aeven
followed by the execution of any of the scheduled tasks.

In this sense I was feeling that there is a waste of resources.

1. What is the best approach to do that?

2. When I start a new tast do I have to create a new thread to run it.
Or is it automatically assigned to a new one by the Tick handler?

-Pam

Cor Ligthert [MVP] ha scritto:
Pam,

为什么其中一个计时器会占用大量资源?
<我将在你的情况下使用的第一件事(假设任务在一个程序中,否则它将是调度程序)

如果它是一个windowsform只是windowsform计时器。

只是我的想法,

Cor
Pam,

Why does one of the timers use a lot of resources?

The first thing I would use in your situation (given that the task are in
one program otherwise it would be the scheduler)

And if it is a windowsform just the windowsform timer.

Just my thought,

Cor






Pamela,

我从来没有遇到过你的问题。主要的问题是我的想法不是计时器,它是b $ b是你分配的内存量。


我认为我会创建一个窗口形式程序(最简单的解决方案)

或使用timmer的windowservice。


比根据计时器使用该程序启动你的其他程序

传递一个参数它必须做什么。


该程序应该以子主程序开头。如果你不知道怎么回答,那么Herfried已经为这个新闻组提供了很多样本​​。


我希望这会有所帮助,


Cor
Pamela,

I never had your problem. The main problem is in my idea not the timer, it
is the ammount of memory you are consequently allocating.

I think that I would create a windowform program (the most easiest solution)
or windowservice that uses a timmer.

Than use that program to start depending on the timer your other program
passing a parameter what it has to do.

That program should than start with a sub main. If you don''t know how, than
reply, Herfried has given much samples for that in this newsgroup.

I hope this helps,

Cor


这篇关于如何安排执行事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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