October 22, 2012

SPLongOperation

Use Case:
SPLongOperation class Sets the Web page image to the image used by the server to indicate a lengthy operation (typically, an animated image with associated text).
So, when you are starting a workflow, or doing some server side processing that can take long period than asp.net request execution timeout period, you can use this class to do such operations.
Usage:
   1:  SPLongOperation.BeginOperation beginOperation = null;
   2:                  if (beginOperation == null)
   3:                  {
   4:                      beginOperation = delegate(SPLongOperation longOperation)
   5:                      {
   6:                          // Long running code here ...
   7:                          longOperation.End(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current, "");
   8:                      };
   9:                  }
  10:                  SPLongOperation.Begin(beginOperation);
 
 
Notes:
You need to import System.Threading. At the end of your operation, generally you do longOperation.End() and page will be redirected to the specified url. If you are doing it in sharepoint dialog, it will automatically close dialog and redirect parent page.

If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment