Click here to Skip to main content
15,900,724 members
Articles / Productivity Apps and Services / Sharepoint / SharePoint 2010
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
3 Sep 2013CPOL 10.3K  
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, 

C#
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. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Infosys Limited
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --