CPU 的时候 !clrstack 信息被我抓出来了。。但是自己看不出问题所在。。有没高人指点下

ptszyf 2012-12-20 12:38:43
0:038> !clrstack
OS Thread Id: 0x3550 (38)
Child SP IP Call Site
00000000063adc90 000007fef4759986 System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.__Canon, mscorlib]].FindEntry(Int32)
00000000063adce0 000007ff00edb625 ZtShop.PageComponent.GetCategoryFileName_Dynamic(Int32)
00000000063add60 000007ff00edb244 ZtShop.PageComponent.GetCategoryFileName(Int32, Boolean)
00000000063addd0 000007ff00edb032 ZtShop.Service.CategoryService.CreateMenu(Int32, System.String, System.Collections.Generic.List`1<Int32>)
00000000063adea0 000007ff00edb064 ZtShop.Service.CategoryService.CreateMenu(Int32, System.String, System.Collections.Generic.List`1<Int32>)
00000000063adf70 000007ff00edb064 ZtShop.Service.CategoryService.CreateMenu(Int32, System.String, System.Collections.Generic.List`1<Int32>)
00000000063ae040 000007ff00edad8d ZtShop.WidgetComponent.GetAllCatMenu(System.String)
00000000063ae090 000007ff00eda1ff ZtShop.WidgetComponent.WidgetParse(System.String, System.String)
00000000063ae1e0 000007ff005362bc ZtShop.WidgetParseFilter.publisher_Begin_Render(System.Object, wojilu.Web.Mvc.MvcEventArgs)





/// <summary>
///
/// </summary>
/// <param name="catId"></param>
/// <param name="curSeldId"></param>
/// <param name="cursPId">当前点击分类的所有父分类</param>
/// <returns></returns>
public static string CreateMenu(int catId,string curSeldId,List<int> cursPId)
{
if (curSeldId == "0") curSeldId = "";
StringBuilder sb = new StringBuilder();

List<Category> cats = Categories.FindAll(p => p.PCatId == catId);
if (cats == null || cats.Count == 0) return "";


sb.AppendFormat("<div class=\"{0}\"><ul>", catId!=0&&IsOpen(catId, curSeldId, cursPId) ? "curselt_div" : "");

foreach (var cat in cats)
{
sb.AppendFormat("<li class=\"{3}\"><a href=\"{0}\">{1}</a>{2}</li>"
, PageComponent.Instance.GetCategoryFileName(cat.Id, true)
, cat.Name
, CreateMenu(cat.Id, curSeldId,cursPId)
, IsOpen(cat.Id, curSeldId, cursPId) ? "curselt_li" : "");

}
sb.AppendFormat("</ul></div>");

return sb.ToString();
}





private static List<Category> _Categories;
public static List<Category> Categories
{
get
{
if (_Categories == null)
{
_Categories = Category.find("order by orderid asc").list();

foreach (var _cat in _Categories)
{
_cat.Des = "";
_cat.Page_Description = "";
_cat.Page_Keyword = "";
_cat.Page_Title = "";
}
}
return _Categories;
}
set {
_LeafCatId = null;
_Categories = value;
}
}
_cat.Page_Title = "";
}
}
return _Categories;
}
set {
_LeafCatId = null;
_Categories = value;
}
}






--------------这是 GetCategoryFileName 方法

public Dictionary<int, string> _categoryFileName_Dynamic = new Dictionary<int, string>();

public string GetCategoryFileName_Dynamic(int categoryId)
{
if (_categoryFileName_Dynamic.ContainsKey(categoryId))
{
return _categoryFileName_Dynamic[categoryId];
}

Category category = Category.findById(categoryId);

if (category == null) return "";

string fileName = "";
if (!string.IsNullOrEmpty(category.Page_Url))
{
fileName = category.Page_Url.Trim('/');
}
else
{
fileName = (ShopConfig.Pre_Url + "-" + Regex.Replace(category.Name, "[^a-zA-Z0-9-]", "-") + "-" + ShopConfig.Aft_Url).Trim('-') + "-c-" + categoryId + ".html";
}

_categoryFileName_Dynamic[categoryId] = UrlPre + "/" + fileName;

return _categoryFileName_Dynamic[categoryId];
}


-------一开始我怀疑是_categoryFileName_Dynamic 并发读写的问题。。不过我用100个线程并发测试过,没有问题。




...全文
273 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
windstore 2013-01-16
  • 打赏
  • 举报
回复
你好,可以参考这篇文章:http://blogs.msdn.com/b/asiatech/archive/2009/05/11/100-cpu-caused-by-system-collections-generic-dictionary.aspx Dictionary不是线程安全的,如果在多线程情况下,有线程在读的时候,另外一个线程写,就有可能导致死锁,进而造成cpu100%
枫c_2012 2012-12-21
  • 打赏
  • 举报
回复
学习下、、
ptszyf 2012-12-21
  • 打赏
  • 举报
回复
没有高人吗?
cs张 2012-12-20
  • 打赏
  • 举报
回复
不懂,帮顶了~~~

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧