I am currently working on TimerJob, which manages some site collections. When the work is done, it scans the list to get the URL of the site SPSite.Exists() , then it calls SPSite.Exists() to check if the site still exists or not.
To check TimerJob, I delete the site collection, but left the corresponding entry in the list. Then I run TimerJob and execute its code in debug mode. When it comes to the point, to check if the SPSite.Exists() site SPSite.Exists() , returns true.
When I run TimerJob a second time for the same site SPSite.Exists() , the SPSite.Exists() method returns false, as it should.
So now I am wondering why SPSite.Exists() returns a false result when I run the task for the first time. Could this be caused by caching?
When I run the same code outside of TimerJob SPSite.Exists() , the correct result is returned each time.
UPDATE
So, I did some more debugging, and it seems that this problem was really caused by some kind of caching mechanism, since this does not happen when the Windows SharePoint Services Timer service was restarted after deleting the test site collection and before TimerJob was started.
At the moment, I cannot imagine any other solution than trying to access the remote site and catch the exception that will be thrown to determine if the site really exists.
UPDATE 2
After several tests, I realized that the problem does not occur for the first call to SPSite.Exists () (in TimerJob) after restarting the timer service. The second call (for another site collection) still leads to a known problem.
UPDATE 3
I am currently using ugly hacking to solve my problem. When SPSite.Exists () returns true, although it doesnβt actually exist, I create an SPSite object and try to throw a FileNotFoundException by calling its Usage property. When exceptions arise, I know that the site does not exist. Oddly enough, after the exception, SPSite.Exists () was reset and returns the correct result (false).
Are there any other suggestions?
Bye flo