Sunday, December 30, 2007

Enhance Data View Performance using Asynchronous Method

Currently I find a way how to enhance a performance to view 10.000 records which taken from Web service layer.

First of all, I can not using any caching because this data will change very often.
Every time the user change something, I need to refresh the data.

I can not use Sql Dependency because all the data are encapsulate on service layer.
I can not perform paging on service layer because it is not provided to me.


Finally, the only way is using Asynchronous Method.

The idea is to display the first page of the records and start retrieving others data asynchronously.

The next time the user want to perform, sorting, filtering or paging, It will force to finish all retreiving data.

This algorithm will force using user thinking time in retreiving huge records rather than forcing user to wait retrieving huge records every time even they just want to see the first page records.

Here is the Algorithm:
=================================
If ( ! IsPostback)
{
* Clear Data set from session
* Retrieve 1st page only and bind to data grid with next/previous paging style
* Create a delegate to retrieve the rest of data
* Start asynchronous call with BeginInvoke.
* Store that delegate and IAsynResult into session.
}
else
{ //( Postback) and user try to bind a data (Sorting, Paging, Filtering)
If (There still no data set in Session)
{
* Take delegate and IAsynResult
* Force delegate to finish by using EndInvoke(IAsynResult)
* Store the data set into Session.
* Bind to data grid with default paging style.
}
else
{
* directly use data set from session and bind to data grid with default paging style.
}
}
===============================

Note:
You may optimize this algorithm by getting a number of record first.
If the number of records is less or equal then the number of first page records, just store that data into session and bind it to data grid with default paging style.
You don't need to perform asynchronous call for this.


The only weakness of this methodology is it will be more thread in your application.

Sunday, December 16, 2007

Notify your custom application from CRM 3.0

This is one of the solution how you notify your application from Microsoft Dynamic CRM 3.0

1. Add Javascripts to notify your application from CRM Custom forms.
a. Open CRM 3.0

b. Go To Settings/ Customization

c. Select what entity you need ( Example phone, email, ...)

d. Go to forms and view on the left tab after you open your entity

e. Select the forms you want to add the scripts.

f. click add properties.

g. There is 2 available event handler (OnSave and OnLoad)

h. Put your javascript there
for example : window.opener('Notify on save');

i. Don't forget to check enable this event before you save it.

j. You may preview it before publish the changes.

g. Don't forget to publish - Action/Publish.

If you forget to publish, It will not take any changes you have made, even you have save it.

Friday, December 14, 2007

Better way to handle thread abort exception in Response.Redirect

private bool m_bIsTerminating = false;

protected void Page_Load(object sender, EventArgs e)
{
if (WeNeedToRedirect == true)
{
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
m_bIsTerminating = true;
// remember to end the method here if
// there is more code in it

return;
}
}

protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
if (m_bIsTerminating == false)
base.RaisePostBackEvent(sourceControl, eventArgument);
}

protected override void Render(HtmlTextWriter writer)
{
if (m_bIsTerminating == false)
base.Render(writer);
}