ChoQueuedExecutionService
In this article, we will go over the one of service provided by Cinchoo framework, ChoQueuedExecutionService. This service used to execute series of methods in orderly fashion. Each operation pushed to this service will be executed in first come first serve basis. Also we can instruct to run each operation with Timeout (ms), Number of retries (in case of error while running), sleep between retries parameters.
Either you can use Global QueuedExectionService (application level service) or instantiate new one locally and use them.
1. Add reference to Cinchoo.Core.dll assembly
2. Namespace Cinchoo.Core
Using Global QueuedExecutionService:
Below sample, inject a delegate to Global execution service and wait for the call to complete.
static void Main(string[] args)
{
IChoAsyncResult result = ChoQueuedExecutionService.Global.Enqueue(() =>
{
Thread.Sleep(5000);
Console.WriteLine("Test Message");
});
result.EndInvoke(); //Optional call, to get the result or wait for the call to finish
}
Creating and using local QueuedExecutionService:
In below sample, we create a local QueuedExecutionService and injecting method to execute.
static void Main(string[] args)
{
ChoQueuedExecutionService service = new ChoQueuedExecutionService("TestQService", false);
IChoAsyncResult result = service.Enqueue(() =>
{
Thread.Sleep(5000);
Console.WriteLine("Test Message");
});
result.EndInvoke(); //Optional call, to get the result or wait for the call to finish
}
Try for yourself!