Take the community feedback survey now.

Anders Hattestad
Jan 13, 2014
  3912
(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
Opal Core Concepts

Before you dive into the code, it's crucial to understand the foundational ideas that make Opal tick. Core concepts are consistent across all its...

K Khan | Sep 13, 2025

Optimizely Opal : Reimagining A Utility Sector Use Case

  Introduction Customer engagement through timely and personalized push notifications plays a crucial role in todays Digital First landscape. In th...

Ratish | Sep 12, 2025 |

A day in the life of an Optimizely OMVP - AEO & GEO: The Future of Digital Visibility with Optimizely

The way people discover content online is undergoing a seismic shift. Traditional SEO is no longer enough. With AI-powered tools like ChatGPT,...

Graham Carr | Sep 12, 2025

Building Optimizely OCP Apps Faster with AI and Coding Assistants

Developing Optimizely Connect Platform (OCP) apps can be a rewarding but complex process—especially when integrating with external APIs. Over the...

Pawel Zieba | Sep 11, 2025