Connected Systems User Group

Los Angeles
Home     Blogs     Contact Us     Links & Downloads     Meeting Archive     Meeting Location     Register     User Groups      
March 13th, 2008 - .Net Asynchronous Programming - Revisited and Demystified

In today’s world of Remote and Disconnected Systems and Extensible Application Architectures, understanding asynchronous programming is more important than ever. This session will provide insight into the patterns, objects, and practices of building high performing multi-threaded applications. Topics will include a deep dive into Events and Delegates, Asynchronous Coding Patterns used in .Net, and Understanding Multi-Threading and Thread Management. 

 

 Download the example file

Asynchronous Programming Sample Code:

This sample code solution contains five demo projects each demonstrating various coding techniques to assist you to better understand Asynchronous programming and its related design patterns.

 

  1. First begin with the project titled ‘Event Demo’ this project show’s code for creating a class with a custom event.
  2. The next demo is the ‘DelegatesDemo’ project. This demo is designed to show the use of delegates and how delegates can be passed from object to object.
  3. The third demo is ‘AsynchronousDataAccess’, this project has three separate forms to demonstrate the use of several built in Asynchronous design patterns in the .Net framework. It illustrates how to retrieve data, invoke web services, and invoke delegates asynchronously without having to create and manage your own threads.
  4. Demo four ‘Threading Demo’ shows code examples on how to create and start your own threads. It also has a simple demonstration of using the .Net ThreadPool class.
  5. The final demo project ‘SynchronizationDemo’ shows some advanced thread synchronization and management techniques including: the Monitor class, Lock syntax, Monitor.Pulse and Monitor.Wait calls, and lastly using an AutoResetEvent to synch threads.

 

To run the demos you will need a default installation of SQL Server (2000 or later) running with the Adventureworks sample database. Also, to run any of the Async web service demos, make sure to first start the web service ‘DataAccessWebService’ by right-clicking on ‘DataAccessService.asmx’ and selecting ‘View in Browser’ from the context menu.

If you would like to try the POP3 client demo in the ‘AsynchronousDataAccess’ project, you will need to open the ‘AsyncMail.cs’ code module and edit the SMTP connection settings in the AsyncMail() constructor to point to your SMTP Server. You will also need to edit the POP3Client connection settings in the Button1_Click() event handler to point to your POP3 server. Although the POP3 client is not written to remove email messages from your server. It is highly recommended that you first retrieve your mail normally (while leaving a copy of the messages on your server) before using the POP3Client.

To run the ‘SynchronizationDemo’ first run the project to see an example of what happens when multiple threads try to all use a shared resource, in this case a SQLConnection. Then open the DataAccessClass.cs code module and locate the comment ‘Section To Synchronize’. In the space below this comment you can copy one of the various code samples found at the end of the file. Only copy and run one of these samples at a time.

 

Special Thanks to:

QuickStart Intelligence, Facility Sponsor
Gerald Walsh, Speaker
 - Gerald Walsh is an independent consultant and instructor focused on software application development and training using Microsoft technologies.
And all those who attended the meeting on March 13th, 2008