Description

AsyncFunc makes it easy to implement Event-based Asynchronous Pattern in .NET.
It allows you to focus on what is really important in your project - business logic.

.NET Framework Version Information

Supported in: 2.0, 3.0, 3.5, 4.0
AsyncFunc can be compiled against any of the listed frameworks. The resultant assembly will be optimized for the target version.

What is Event-Based Asynchronous Pattern?

It one of the recommended patterns for implementing asynchronous operations in .NET. In contrast with Classic Asynchronous Pattern (IAsyncResult), it is optimized for usability and easily integrates with visual designers. A good summary can be found at Event-based Asynchronous Pattern Overview.
It has the following advantages:
  • Visual Studio support
  • it is a right way to create asynchronous version of existing synchronous methods
  • better control over number of simultaneous operations (single invocation scenario)
  • usability (all event handlers are invoked on the 'proper' thread, no UI synchronization needed)
More information can be found at: Multithreaded Programming with the Event-based Asynchronous Pattern

Why AsyncFunc?

If you are really reading this section then you haven't probably tried to implement this pattern on your own. Without AsyncFunc I'm sure you would start with a sample at How to: Implement a Component That Supports the Event-based Asynchronous Pattern. But then you would realize that if you need more than 450 lines of code to search for a prime numbers, then making your business logic asynchronous would require an enormous codebase. Moreover, you could also notice that there is no sample for single invocation scenarios (IsBusy). Therefore, you would need to implement it on your own and deal with all synchronization issues you may come across (there are some, I know it).

I had this problem and after implementing second component with almost the same code I decided that I will extract boilerplate parts and create reusable, generic solution. Of course there are many different scenarios for asynchronous operations. That is why I decided to create several classes that cover common scenarios.

AsyncFunc features

  • complete implementation of Event-Based Asynchronous Pattern
  • no need to define new delegates
  • no need to define new completion argument classes
  • no need to bother about synchronization
  • support for cancellation
  • support for progress reporting
  • support for single invocation scenarios
  • naming similar to existing delegates (Func<> -> AsyncFunc<>, Action -> AsyncAction<>)
  • low learning curve
  • independent of presentation technology (can be used in WindowsForms, WPF, ...)

MSDN vs AsyncFunc

If you are still not convinced, have a look at how sample code from msdn can be simplified with AsyncFunc. The code is slightly different from the original msdn version as I removed anything that was not directly related to the problem. The result is quite impressive, msdn version is almost two times bigger.
MSDN vs AsyncFunc

Videos

This short series shows how to make existing code run asynchronously:

Last edited Feb 11, 2011 at 6:22 PM by StanislawSwierc, version 4