Friday, January 15, 2010

SPLongOperation - delay in redirection after the operation

Scenario:
Many of us may be aware of the SPLongOperation object provided by SharePoint.
Just to refresh once again, SPLongOperation is SharePoint's “Operation in Progress” spin wheel.
It could be used when time taking operations such as creating a site, running a worklow, looping through large list of items etc.. take place on the page. There are many ways to accomplish the same through AJAX. However SPLongOperation scores points for it's SharePointy look.

It renders the below on screen:

void PerformALongOperation()        
{
  using (SPLongOperation operation = new SPLongOperation(this.Page))
  {
    operation.LeadingHTML = "Creating site";
    operation.TrailingHTML = "Please wait while the project site is being created for New Site";
    operation.Begin();

    //Create a site, some lists in it, and then start a workflow

    operation.End(urlToRedirect);
  }
}

So far so good. It looks very straight farward to use this class.

Problem:

After the operation ends, every time we encountered a delay of exactly 32 seconds before the redirection happened.

We have tried the below:
operation.End(urlToRedirect);
HttpContext.Current.Response.Redirect(urlToRedirect);
SPUtility.Redirect(urlToRedirect);

Hoewver nothing seemed to work for us.
So finally javascript redirection worked out for us:
ClientScript.RegisterClientScriptBlock(this.GetType(), "script", String.Format("", urlToRedirect));

1 comment:

  1. Hello!
    I have a similar article in my blog. Additionally I explained the reason of ThreadAbortException, which is sometimes thrown. The article is here - http://dotnetfollower.com/wordpress/2011/08/sharepoint-how-to-use-splongoperation/
    Thanks!

    ReplyDelete