Long Operations in SharePoint

Posted Monday, July 16, 2007 4:37 PM by C-Dog's .NET Tip of the Day

Have you written something in SharePoint that is going to take a while? Trust me it is not hard to do. Ever wondered how they make the spinning gears shows up during a long operaton? Well in fact it is pretty easy. Simply create an instance of the SPLongOperation object (Microsoft.SharePoint.dll). Make a call to the BeginOperation method, put your code in and then make a call to EndOperation passing it a URL of what page to load when it is finished. That is all there is too it. Here is an example.

SPLongOperation longOperation = new SPLongOperation(this.Page);
longOperation.Begin();

// my long operation
System.Threading.Thread.Sleep(10000);

longOperation.End("default.aspx");

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=373

Filed under: