4

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.

ocodo
  • 29,401
  • 18
  • 105
  • 117
  • 1
    I'm not quite sure what you're looking for here, methods called in sequence without making any effort to invoke multiple threads will run sequentially with the next method being invoked when the last ends. If you want to put predefined pauses between methods this can be done by making the current thread sleep for a given number of seconds or looping with an exit condition that requires it to be on or after a given time. Can you clarify what you require? – Robb Dec 13 '10 at 00:13
  • 1
    IMO its pretty obvious what he wants to do. Its even a so common requirement that Microsoft have implemented dedicated support for it via its .ContinueWith() method on a Task object in the Task Parallel Library. – Pauli Østerø Dec 13 '10 at 00:21

3 Answers3

2

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.

2

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));
Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
0

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

rcravens
  • 8,320
  • 2
  • 33
  • 26