How to perform an Asynchronous Insert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dba123

    #1

    How to perform an Asynchronous Insert

    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
  • Dave Sexton

    #2
    Re: How to perform an Asynchronous Insert

    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 InsertDataInvok er();

    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (Page.IsPostBac k)
    // insert data if the page has been posted back
    {
    // create the delegate to be invoked asynchronously
    InsertDataInvok er invoker = new InsertDataInvok er(InsertDataAs ync);

    // invoke the InsertDataAsync method asynchronously and
    // use an anonymous method to clean up after it's done
    invoker.BeginIn voke((AsyncCall back) delegate(IAsync Result result)
    {
    // end the invocation.
    // if your method returns a value other than void
    // this is where it can be retrieved
    invoker.EndInvo ke(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" <dba123@discuss ions.microsoft. comwrote in message news:6D740686-B0DE-4FF2-ADD2-271E5BFED55B@mi crosoft.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

    Comment

    Working...