SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use SPLongOperation like in the snippet below. When I run SPDisposeCheck, I get an error. So I have these questions:

  1. Wouldn't the using statement call Dispose() on SPSite when execution is completed?
  2. How can I give a friendly error message, regardless of the type of exception thrown during the long runnig process?

    protected void btn_click(object sender, EventArgs e)
        // ..... removed for brevity
        SPLongOperation longOp = new SPLongOperation(this.Page);
        try     //getting error: Disposable type not disposed: Microsoft.SharePoint.SPSite
            using(SPSite oSite = new SPSite(SPContext.Current.Site.Url))
                using(SPWeb oWeb = oSite.OpenWeb(client))
                    // do long running process
                    // throw new Exception("Something went wonky!");
        catch (ThreadAbortException)
        catch (Exception ex)
share|improve this question
You should do using(SPLongOperation longOp = new SPLongOperation(this.Page)) {...} to get rid of Disposable type not disposed error. – m.jedrzej Oct 24 '12 at 7:49
Yes. Moving the SPLongOperation inside the try block and using a 'using' statement worked. – JSRookie Oct 27 '12 at 15:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.