Project Description

This is a library which provides a generic typed Pool for running Tasks in an extra thread.

Documentation

It accepts a List of Tasks. Once Run() called, the tasks will be run in sequence.
Parallelism will be a future mark.

Each Action can return a generic Object via an raised "OnDone"-Event. Also the pool has a property telling the progress in percent.
The Pool raises an Event "OnAllDone".

Example Use

 

// As best not in a form, better in bussiness layer
private void SetUp() {
    ActionPool = new BackgroundActionPool<string, string[]>(); 
    // ActionPool with Actions performing String as parameter and String[] as return value.

    this.Files = Directory.GetFiles(basedir, "*.jpg", SearchOption.AllDirectories).ToList();
    foreach (var file in Files) {
        var action = ActionPool.Create(CreateThumbnail, file);
        action.OnDone += action_OnDone; // Show thumbnail
        ActionPool.Add(action); 
} // foreach end ActionPool.OnNextProgress += ActionPool_OnNextProgress; ActionPool.RunCanceled += ActionPool_RunCanceled; ActionPool.Run(); } // Create Thumbnail with String[] Func(String param)-signature private String[] CreateThumbnail(String filename) { var tempFilename = Path.GetTempFileName(); Image image = Image.FromFile(filename); var thumb = ScaleImage(image, 120, 120); thumb.Save(tempFilename); return new String[] { filename, tempFilename }; }