用于定时操作的 C# 库

发布于 2024-10-07 22:34:20 字数 82 浏览 0 评论 0原文

您知道有哪些 C# 库可以让您对一系列操作进行排序吗?每个动作在前一个动作完成后执行,或者更好的是,在特定时间间隔发生后执行。

谢谢。

do you know of any C# libraries that allow you to sequence a series of actions, ie. each action executing when the previous has finished, or better yet, after a specific time interval has occurred.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

破晓 2024-10-14 22:34:20

查看 http://msdn.microsoft.com/en-us/library/dd537609 .aspx

Task.ContinueWith 方法让
您指定要在以下时间启动的任务
先行任务完成。

例子

var task = Task.Factory.StartNew(() => GetFileData())
                                       .ContinueWith((x) => Analyze(x.Result))
                                       .ContinueWith((y) => Summarize(y.Result));

Look at http://msdn.microsoft.com/en-us/library/dd537609.aspx

The Task.ContinueWith method let
you specify a task to be started when
the antecedent task completes.

Example

var task = Task.Factory.StartNew(() => GetFileData())
                                       .ContinueWith((x) => Analyze(x.Result))
                                       .ContinueWith((y) => Summarize(y.Result));
陌生 2024-10-14 22:34:20

对于计时尝试quartz.net。对于同步操作,请使用例如。事件,等待句柄Monitor.Wait( )Monitor.Pulse() ...

否则您可以处理一组操作,例如,

var methods = new List<Func>
{
    FooMethod1,
    FooMethod2
}
foreach (var method in methods)
{
    method.Invoke();
}

但这只有在您没有主持人方法(顺序处理)时才有意义或者你的方法不应该互相了解。

for timing try quartz.net. for synchronizing actions, use eg. events, waithandles, Monitor.Wait() and Monitor.Pulse() ...

otherwise you can handle a set of actions, eg

var methods = new List<Func>
{
    FooMethod1,
    FooMethod2
}
foreach (var method in methods)
{
    method.Invoke();
}

but this only makes sense, if you do not have a moderator-method (sequencial processing) or your methods should not know about each other.

月棠 2024-10-14 22:34:20

对于计划任务,您正在寻找支持 cron 作业的库。这是我在项目中使用的一个。

http://blog.bobcravens。 com/2009/10/an-event-based-cron-scheduled-job-in-c/

存在很多库。我发现很多功能丰富但有点笨重。

希望这有帮助。

鲍勃

For scheduled tasks you are looking for a library that supports cron jobs. Here is one I used in a project.

http://blog.bobcravens.com/2009/10/an-event-based-cron-scheduled-job-in-c/

A lot of libraries exist. I found many are feature rich and a bit heavy.

Hope this helps.

Bob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文