Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Anders Hattestad
Jan 13, 2014
  3548
(0 votes)

Error: Deadlock risk detected…..

I got this error “Deadlock risk detected.Trying to read a page from the same thread that is already trying to read the same page”  and want to share with you what was my problem.

I can seems that when you first access a page data, and if that page data object make a call to itself (direct or indirect) you will get this error.

I got it in my file selector property and I needed to rewrite the Value method.

The problem was that if you in the file selector added files from the page folder to the page the

System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(“/pagefiles/currentPageID/”) this code will make a new call to get the page and make a deadlock.

The trick is to move the code from Value to the SaveData method. So instead of changing the code each time it’s read from the database, only to each time it’s saved.

So the new code for instead of the Value method in  the PropertyFiles.cs class is

Code Snippet
  1. public override object SaveData(PropertyDataCollection properties)
  2. {
  3.     var str = this.LongString;
  4.  
  5.     if (str != null)
  6.     {
  7.         var doc = new HtmlDocument();
  8.         doc.LoadHtml(str);
  9.         var refLinks = "";
  10.         foreach (var item in doc.DocumentNode.ChildNodes)
  11.         {
  12.             if (item.Name == "div" && item.Attributes.Contains("data-href") && item.Attributes["data-href"].Value != "")
  13.             {
  14.                 var href = item.Attributes["data-href"].Value;
  15.                 var inner = "";
  16.                 refLinks += "<a href=\"" + href + "\" class=\"ignore\" style=\"display:none;\">" + href + "</a>";
  17.                 item.Attributes.Remove("style");
  18.  
  19.  
  20.                 if (href.EndsWith("/"))
  21.                 {
  22.                     item.Attributes.Add("style", "border:1px solid black;margin-bottom:5px;");
  23.  
  24.                     inner = "<div>";
  25.                     inner += "<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('" + href + "');obj.click();\" />delete";
  26.  
  27.                     inner += "</div>";
  28.                     var dir = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(href) as UnifiedDirectory;
  29.                     if (dir != null)
  30.                     {
  31.                         inner += "All files from folder:<br />" + dir.VirtualPath;
  32.                         foreach (UnifiedFile fil2 in dir.Files)
  33.                         {
  34.  
  35.                             if (BaseMedia.IsMedia(fil2.VirtualPath))
  36.                             {
  37.                                 refLinks += "<a href=\"" + fil2.VirtualPath + "\" class=\"ignore\" style=\"display:none;\">" + fil2.VirtualPath + "</a>";
  38.                                 inner += "<div style=\"float:left;\">";
  39.                                 inner += "<img style=\"width:80px;height:80px;\"  src=\"/FileCache" + fil2.VirtualPath + "/width_80.height_80.mode_crop.jpg\" data-org=\"" + fil2.VirtualPath + "\" title=\"" + fil2.VirtualPath + "\" />";
  40.                                 inner += "</div>";
  41.                             }
  42.                             else
  43.                             {
  44.                                 refLinks += "<a href=\"" + fil2.VirtualPath + "\" class=\"ignore\" style=\"display:none;\">" + fil2.VirtualPath + "</a>";
  45.                                 inner += "<div title=\"" + fil2.VirtualPath + "\">" + fil2.Name + "</div>";
  46.                             }
  47.                         }
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     item.Attributes.Add("style", "border:1px solid black;float:left;margin-right:5px;margin-bottom:5px;");
  53.                     var filname = Path.GetFileName(href);
  54.                     var path = href.Substring(0, href.Length - filname.Length);
  55.                     inner = "<div>";
  56.                     inner += "<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('" + href + "');obj.click();\" />delete";
  57.  
  58.                     inner += "<input type=checkbox onclick=\"$(this).parent().parent().attr('data-href','" + path + "');var obj=$(this).closest('.ownerDiv').find('.actionField');$(this).parent().html('All files from folder:<br />" + path + "');obj.val('" + href + "');obj.click();\" />all<br/>";
  59.  
  60.  
  61.  
  62.                     item.Attributes.Remove("onclick");
  63.                     if (BaseMedia.IsMedia(filname))
  64.                     {
  65.                         inner += "<img style=\"width:80px;height:80px;\" src=\"/FileCache" + href + "/width_80.height_80.mode_crop.jpg\" data-org=\"" + href + "\" title=\"" + href + "\" />";
  66.  
  67.                     }
  68.                     else
  69.                     {
  70.                         inner += "<div title=\"" + href + "\">" + filname + "</div>";
  71.                     }
  72.                     inner += "</div>";
  73.                 }
  74.  
  75.                 item.InnerHtml = inner + "<div style=\"clear:both;\"></div>";
  76.  
  77.             }
  78.         }
  79.         return doc.DocumentNode.OuterHtml;
  80.              
  81.     }
  82.     else
  83.     {
  84.         return this.Value;
  85.     }
  86. }
Jan 13, 2014

Comments

Apr 24, 2017 04:47 PM

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog