Overview

Fluent Task

Summary

FluentTask allows you to run operations in separate thread yet receive success, failure and progress update on the WPF UI thread so that you can have a responsive UI and carry out expensive operations in background. It's convenient to use than BackgroundWorker component. No need to decare events and preserve stuffs in private variables to access it from different event callbacks. You can return data from parallel thread to the success/fail callback safely in a strongly typed manner.

Examples

new FluentTask<int>()
                 .DoWork(
                     () =>
                         {
                             Console.WriteLine("Do work");
                             Thread.Sleep(TimeSpan.FromSeconds(2.5));
                             return (int)Math.Exp(new Random().NextDouble());
                         })
                 .OnException(Console.WriteLine)
                 .SetDefaultResultOnException(-1)
                 .SetTimeout(TimeSpan.FromSeconds(3))
                 .SetDefaultResultOnTimeout(-2)
                 .OnTimeout(() => Console.WriteLine("Timeout"))
                 .OnComplete(Console.WriteLine)
                 .RunAsync();