spicy.net: Asynchoronous Data Fetching...

spicy.net

Friday, February 16, 2007

Asynchoronous Data Fetching...

We would have faced Session Timeout Issue and some runtime error if we have huge number of records to be displayed in web. To eliminate this we can go for a mixture of Asynchoronous call and caching. I have explained in macro level and you can tune based upon your requirements.
Please follow these steps...
Step1:
/*Declare a Delegate*/
private delegate void ExampleDelegate();
Step2:
/*Map the delegate to a function which is going to be a asynchronous*/
ExampleDelegate dlgInstance = new ExampleDelegate(GetSmartsData);
Step3:
/*Invoke the call back function*/
dlgInstance.BeginInvoke(new AsyncCallback(DrawGrid),null);
Step4:
/*Actual Async enabled Function*/
private void GetSmartsData() { Populate the date from the DB asynchronously.Let us assume the data in dataset object ds.}
Step5:
/*Call back function with caching */
private void DrawGrid(IAsyncResult results) {
Cache.Insert("FirstGrid",ds,null,System.DateTime.Now.AddMinutes(15),new System.TimeSpan(0));
}

It is working fine in my application.Please let me know if any issues. Happy coding.

0 Comments:

Post a Comment

<< Home