By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,130 Members | 2,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,130 IT Pros & Developers. It's quick & easy.

How to perform an Asynchronous Insert

P: n/a
I need to perform Asynchronous Inserts using DAAB. So far I have a method
which does an insert but how can I do this Asyncronously so that it does not
affect the load on our public production website? This question is wide open
but make sure you give me some ideas in context with DAAB syntax. Some
thoughts are threading, ATLAS, etc. but I have no clue how to even approach
an Asynchronous Insert or any techniques at this point. Also, I want
something that is safe.

--
dba123
Jul 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
}

--
Dave Sexton

"dba123" <db****@discussions.microsoft.comwrote in message news:6D**********************************@microsof t.com...
>I need to perform Asynchronous Inserts using DAAB. So far I have a method
which does an insert but how can I do this Asyncronously so that it does not
affect the load on our public production website? This question is wide open
but make sure you give me some ideas in context with DAAB syntax. Some
thoughts are threading, ATLAS, etc. but I have no clue how to even approach
an Asynchronous Insert or any techniques at this point. Also, I want
something that is safe.

--
dba123

Jul 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.