Want to see the nice SharePoint spinner while you perform long running operations? Here's how:
using (SPLongOperation op = new SPLongOperation(this.Page)) {
op.LeadingHTML = "Please wait";
op.Begin();
try {
// Do some stuff that takes a long time
op.End("Finished.aspx");
} catch (ThreadAbortException ex) {
} catch (Exception ex) {
op.End("Error.aspx");
}
}
When you call op.Begin() you'll see the SharePoint spinner until you call op.End(). Notice that I am using a try/catch block, if you don't do this and an error occurs then the user will be stuck in perpetual spinner land. To avoid this send the user to an error page when an error happens.