Asynchronis Pattern (Part 4)

Part 4

The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many of the complex issues inherent in multithreaded design.

Using a class that supports this pattern can allow you to:

  • Perform time-consuming tasks, such as downloads and database operations, “in the background,” without interrupting your application.
  • Execute multiple operations simultaneously, receiving notifications when each completes.
  • Wait for resources to become available without stopping (“hanging”) your application.
  • Communicate with pending asynchronous operations using the familiar events-and-delegates model. For more information on using event handlers and delegates, see Events and Delegates.

By using the Asynch pattern in the LightSwitch HTML client the developer can build responsive user interfaces that are capable of doing a lot of work. Typically we use a BackgroundWorker component when building simple multi-threaded applications but as we start to build more complex solutions we will want to build a set of methods, generally analogous to the ones working on the current thread, to handle the computing. The biggest challenge that I have found in doing this kind of work is the lack of ability to update across threads. With some ingenuity you can overcome this nicely. LightSwitch HTML client solves many of those issues for you as it generates the application.

In the HTML client, we chose to expose promise objects to represent asynchronous work. Promise objects provide the most flexible set of options when working in an asynchronous environment and make it easier to structure code in its logical order of execution.

There are a number of promise object implementations available. We chose to utilize the WinJS implementation of promise objects as it was one of the more complete offerings and provided technical alignment with the Windows 8 development experience.

Additional Reading

Event-based Asynchronous Pattern Overview on MSDN
Using Promise objects with LightSwitch

Leave a Reply