Skip to main content

Posts

Showing posts with the label Asynchronous

Extending WhenAny,WhenAll like feature to get the task as soon as it completes

While working with list of task, we only get two built in options to retrieve task info for completion. First is WhenAny and other WhenAll. WhenAny can be used when any of the given tasks gets completed first where as WhenAll notifies when all of the task gets completed. There is no option to know each task as soon as it gets completed. I was going through  Pro Asynchronous Programming with .NET  book which shows better option to deal with notification of task completion efficiently. To return the task on completion,  TaskCompletionSource  will be used . Through TaskCompletionSource,  Task  could be created and with provided inbuilt methods outcome can be handled. This can be also helpful to wrap up legacy codes as well to built up task. Let's directly look in to core code to return task based on completion. /// <summary> /// Order by completion for Task. /// </summary> /// <typeparam name="...

Displaying progress status in asynchronous programming

UX is most important in any application and responsive application is an add-on to make UI free by running long running task in background. Sometimes we need to show more useful information about long running task to keep user informed about progress. In this article, we will be looking into showing up progress status for long running process with Task Parallel Library (TPL). In this particular example, we will be creating a Console application to re-size any amount of jpg files under directory with new image dimension but our main focus would be on showing progress status. Prior to .Net 4.5 Framework version, there was no inbuilt mechanism to show status of task. If it was needed, then we need to create event handler on class that is processing the long running task with custom defined event argument for progress status class and then subscription need to be done on consuming class for getting progress information. This was better and tidy approach for getting progress status...