I created these properties in my static helper class.
private static ServerManager IISServerManager
{
get
{
if (mIISServerManager== null)
{
mIISServerManager= new ServerManager();
}
return mIISServerManager;
}
}
private static SiteCollection Sites
{
get
{
try
{
return IISServerManager.Sites;
}
catch (Exception)
{
return null;
}
}
}
When I'm calling Helper method
public static bool VirtualDirectoryExists(string dirName, string siteName)
{
if (!String.IsNullOrEmpty(dirName) && (Sites != null))
{
Site site = Sites[siteName];
...
in code that uses this helper (in Main thread) it retrieves all sites and their properties correctly.
On the other hand, when I'm calling it in code that uses this helper (in background worker thread) SitesCollection is retrieved, but code freezes on getting site with indexer [siteName]
Site site = Sites[siteName];
(it looks like deadlock, but there is no locking from my side)