Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
        longOp.Begin();
    
        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!");
    
                }
            }
    
            longOp.End(redirectUrl);
        }
        catch (ThreadAbortException)
        {
    
        }
        catch (Exception ex)
        {
            SPUtility.TransferToErrorPage(ex.ToString());
        }
    
    }
    
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

 
discard

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

Browse other questions tagged or ask your own question.