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





0/5 (0 vote)
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.