65.9K
CodeProject is changing. Read more.
Home

You cannot invalidate the SPRequest object while it’s in use in SharePoint 2010

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 3, 2013

CPOL
viewsIcon

10421

Cause: If you are passing SPWeb object in the thread method, you will get this exception.

Introduction

When you are doing coding, you may get the above exception. This exception may due to passing the SPWeb instance to a thread method. 

Using the code

Suppose in the main thread , you have created the SPWeb object and pass this object to a thread method, like this, 

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
    using (SPWeb web = site.OpenWeb())
    {

        activateThread = new Thread(delegate()
        {
            this.Activate(web);
        });
        activateThread.Start();
   }
}

Here the SPWeb object web is passing to the thread method Activate. The issue is because of this only. 

Remedy 

Don't pass the SPWeb object from main thread (Application Thread) to a thread method. Instead create the SPWeb object inside the thread method (here Activate method) and dispose the web object there.