Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 24 comments about this article.
Article source: CoDe (2003 - May/June)


Article Pages:  1  2 3 4 5 - Next >


Asynchronous Calls in .NET

When you make a method call on an object, typically you must block the client while the object executes the call, and control returns to the client only when the method completes execution and returns.However, there are quite a few cases where you want to call methods asynchronously?that is, you want control to return immediately to the client while the object executes the called method in the background, and then somehow let the client know when the method execution is completed. Such an execution mode is called asynchronous method invocation and the action is an asynchronous call. Asynchronous calls allow you to improve availability, increase throughput and performance, and make your applications more scalable.

Standard, Consistent Mechanism

In the past, developers often had to create their own proprietary mechanism to asynchronously invoke calls on their components. One recurring mechanism was to have the object spin off a worker thread to process the client's request and immediately return control to the client. The object would later signal the client somehow when the call completed (if the client wanted to know), and the client had to distinguish between multiple method completions. These mechanisms were difficult to develop and test, and they forced developers to spend a disproportionate amount of their time reinventing the wheel instead of adding business value to the application. In addition, such solutions coupled the clients to the objects, and were not consistently designed or implemented. Different vendors provided slightly different solutions, requiring at times different programming models on the client side. This predicament diminished the benefits of component-oriented programming because the component developer had to make some assumptions about the client's way of using the component, and vice-versa.

The .NET mechanism for asynchronous calls is a mainstream facility used consistently and pervasively across the .NET application frameworks and base classes. .NET asynchronous calls are an essential addition to your arsenal as a component developer. Implementing robust asynchronous execution on your own is a demanding task, requiring a lot of effort spent on design, implementation, and testing.

Requirements for an Asynchronous Mechanism

To make the most of the various options available with .NET asynchronous calls, you first need to understand the generic requirements set for any modern, component-oriented asynchronous calls support:

Use the same component code for both synchronous and asynchronous invocation. This allows the component developer to focus on the business logic, and facilitates using a standard mechanism.

A corollary of the first requirement is that you let the client decide whether to use the component synchronously or asynchronously. That, in turn, implies that the client will have different code for each case (whether to invoke the call synchronously or asynchronously).

The client should be able to issue multiple asynchronous calls, and manage multiple asynchronous calls in progress. The client should be able to distinguish between multiple methods as they complete their tasks.

By that same token, the component should be able to serve multiple concurrent calls.

When component methods have out-going parameters or return values, these parameters are not available when control returns to the client. The client should have a way of getting these parameters or results when the method completes.

"
Asynchronous calls allow you to improve availability, increase throughput and performance, and scale up your application
"

Similarly, errors on the component's side should be propagated to the client side. An exception thrown when the method executes should be played back to the client later on.

The last item is less of a requirement and more of a design guideline: The asynchronous calls mechanism should be straightforward and simple to use. For example, the mechanism should hide its implementation details as much as possible, such as the worker threads used to dispatch the call.

The client has a variety of options for handling method completion, all of which support these requirements. The client issues an asynchronous method call, and then can choose to:

Perform some work while the call is in progress, and then block until completion.

Perform some work while the call is in progress, and then poll for completion.

Receive notification when the method has completed. The notification will be in the form of a callback on a client-provided method. The callback should contain information identifying which method has just completed and its return values.

Perform some work while the call is in progress, and then wait only for a pre-determined amount of time and then stop waiting, even if the method execution has not completed yet.

Wait simultaneously for completion of multiple methods. The client can choose to wait for any or all of the pending calls to complete.

.NET offers all these options to clients, which can be confusing when you first start using asynchronous calls. This article will demonstrate each option and recommend when (or if) to use them. First, though, we need to discuss delegates.

&

By: Juval Lowy

Juval Löwy is a software architect and the principal of IDesign, a consulting and training company focused on .NET architecture consulting and advanced .NET training. This article contains excerpts from his latest book (Programming .NET Components 2nd Edition (O'Reilly, 2005). Juval is a frequent presenter at development conferences and Microsoft's Regional Director for the Silicon Valley.

Over the last three years Juval has been part of the Strategic Design Review process for .NET 2.0.

Microsoft recognized Juval as a Software Legend as one of the world's top .NET experts and industry leaders.

Contact him at www.idesign.net

Fast Facts

Almost every application requires a mean for asynchronous method invocation. Invoking methods asynchronously involves a substantial amount of infrastructure: keeping track of methods in progress, multithreading, and error handling. Fortunately, .NET provides a standard way for asynchronous invocation, which is consistent and available to every component and client.



Article Pages:  1  2 3 4 5 - Next Page: 'What Delegates Are, Actually' >>

Page 1: Intro
Page 2: What Delegates Are, Actually
Page 3: Asynchronous Calls Programming Models
Page 4: Polling or Waiting for Completion
Page 5: Performing Asynchronous Operations without Delegates

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4.5 out of 5

106 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      AppsWorld Europe

 

SSWUG