The main purpose behind this simple solution is to have some of the new task management features on older .NET applications and, of course, testing some of the TPL classes that the library provides.
- Serilog for logging.
- Moq and xUnit for the test suite
- FluentAssertion for the assertions
var scheduler = new TPLTaskScheduler();
var workItem = new WorkItem(() =>
{
Thread.Sleep(2 * 1000);
Console.WriteLine("something is happening here uh");
});
scheduler.EnqueueWork(workItem); //eventually it will be completed
//or if you want use the await/async keyworkds
var bananas = new WorkItem<string>(() => "🍌🍌🍌");
var monkeys = new WorkItem<string>(() => "🙊🙊🙊");
var mon = await monkeys; //if you use the IWorkItem<Type> interface
await bananas;//if you use the plain IWorkItem interface
Console.WriteLine(mon);
Console.WriteLine(bananas.Result);
var task = Task.Factory.StartNew(
() =>
{
Thread.Sleep(2 * 1000);
Console.WriteLine("🙊 eats the 🍌 after a while");
}
, CancellationToken.None
, TaskCreationOptions.None
, scheduler);