Sharepoint CritSit and Best coding practice

on August 9, 2006

Was reading about branding sites when I came to hit Daniel Mcpherson Blog at msdn. A very nice article on problem resolution. If you want to know what a CritSit is, have a look at the article.

In the same line, here is a quite new paper on coding Best Practices: Using Disposable Windows SharePoint Services Objects.

I just finished the development of two Web Parts. They were pretty complex as they use Asyncronous call, Impersonnation using the application pool account and a Custom Application Domain. I will write more on this solution later as I had to find many solution to many problems all along the development. What I want to show here is that we need to properly release objects we create. In particular SPWeb and SPSite. This msdn article shows how it “should” be done.

In the real life though, another problem may arise if you properly Dispose your objects. Let say you have two web parts on the same page. They both use using SPWeb and/or SPSite. When you refresh the page a mix of object can occur. I experienced this situation: Properly dispoing the object in Web Part #2 make Web Part #1 to fail to load. As soon as I commented the lines to dispose SPWeb, it started to work again. It seems that you can kill objects of a Web Part from another…

Since it now works, I did not take more times to deeply investigate what appens on both web parts during the executions. If you know more about this… Let me know…

ShareThis