C# Libraries for timed actions
do you know of any C# libraries that allow you to开发者_StackOverflow 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.
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));
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.
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
精彩评论