Hi dba123,
I don't see how asynchronous calls are going to help reduce the 'load' on your server. After all, your server is still processing
the method, asynchronous or not. If you have a method that is really time consuming and you want to reduce the amount of time it
takes for web users to download your pages, particularly when you have a lot of concurrent requests that access your database, you
can use an asynchronous call to do your data access work and allow ASP.NET to complete the request asynchronously. You should
create a Web Farm, Web Garden or use a caching arcitecture if you want to reduce the amount of processing required for each request.
If you decide that you still need asynchronous calls you can use the new async page feature in ASP.NET 2.0. Realize, however, that
async calls using the new feature will cause the response to wait until all registered asynchronous calls are completed. This is
useful if you need the return values of your async methods or if your methods change important 'state' information needed to render
your page such as a flag that indicates the DAL work was successful and you want to render a 'success' message on the page.
Otherwise, you can just call a delegate asynchronously.
BTW, ATLAS is for client-side callbacks and I don't think it can help to address your concern about the load on the server.
Here's an example of an asynchronous call on a delegate. This code will work regardless of your data access architecture. It
simply calls a method asynchronously using a ThreadPool thread in a Page.Load event handler. You can do any work that you'd like
within the method that is executed asynchronously:
private delegate void InsertDataInvoker();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
// insert data if the page has been posted back
{
// create the delegate to be invoked asynchronously
InsertDataInvoker invoker = new InsertDataInvoker(InsertDataAsync);
// invoke the InsertDataAsync method asynchronously and
// use an anonymous method to clean up after it's done
invoker.BeginInvoke((AsyncCallback) delegate(IAsyncResult result)
{
// end the invocation.
// if your method returns a value other than void
// this is where it can be retrieved
invoker.EndInvoke(result);
}, null);
}
}
/// <summary>
/// This method is executed asynchronously by the
/// <see cref="Page.Load" /> event handler to insert data.
/// </summary>
private void InsertDataAsync()
{
// TODO: insert data as normal
}