PowerTCP Mail for .NET
Asynchronous Operation
Send comments on this topic.




Synchronous vs Asynchronous

The decision of whether to use synchronous or asynchronous methods can be crucial and have an impact on the complexity of your code and the user experience.

The following lists discuss some of the characteristics of synchronous and asynchronous methods in PowerTCP.

Synchronous Methods

Asynchronous Methods

Most applications written with PowerTCP will be synchronous. The reasons for this are not purely due to the ease-of-use of synchronous methods. Synchronous methods are ideal for automated processes that can execute a blocking method for a long period of time. In addition, synchronous methods can work well for interactive applications. The DoEvents property controls the processing of user interface messages while a synchronous method is executing. This means that while a synchronous method is executing, other portions of the application will be able to respond to events (for example, button or menu clicks).

Asynchronous methods, on the other hand, provide a great deal of power. When an asynchronous method is called, the method will execute on a thread separate from the calling thread. Such operation is useful when an action is time consuming and other code needs to execute without waiting for the initial operation to complete. In addition, the user interface will be most responsive when asynchronous methods are used.

EndXXX

An EndXXX event is a generic term to describe any event used by PowerTCP Mail for .NET that begins with the word "End". These events are reserved to notify the application of a process being completed. In addition, all EndXXX events are raised by the completion of a corresponding BeginXXX method.

Comparison With Other Techniques:

PowerTCP products employ a unique technique for handling asynchronous completion notification:

  1. As compared to using the delegate technique, by using Events for completion notification, PowerTCP gives developers strong environment support for adding event handlers.
  2. Before raising the completion event, the component calls the (internal) delegate's Smtp.EndInvoke method, capturing any Exceptions thrown during asynchronous execution. Using this technique, PowerTCP ensures that all asynchronous calls are properly terminated, and consequently eliminates one programming step that would normally have to be accomplished by our users.
  3. When any BeginXXX method is used, PowerTCP checks for the appropriate event handler and throws an InvalidOperationException if none is found. This action ensures proper usage.

We believe that this approach has made asynchronous communications programming as easy as it gets, providing our users with superior value.

Special Notes About EndXXX Events:

Be sure to check the e.Exception property for exceptions that occurred during the asynchronous method call. If the operation failed to complete, the presence of an Exception object may be your only indication that the operation failed.

It is a very good programming practice to surround your event code with a try/catch block. If you do not do so and generate an exception within your code, a default exception handler will display your exception to the user of your application using a MessageBox.

 

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.