当前位置:编程学习 > C#/ASP.NET >>

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

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个线程并发测试过,没有问题。




--------------------编程问答-------------------- 不懂,帮顶了~~~ --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 没有高人吗? --------------------编程问答-------------------- 学习下、、 --------------------编程问答-------------------- 你好,可以参考这篇文章:http://blogs.msdn.com/b/asiatech/archive/2009/05/11/100-cpu-caused-by-system-collections-generic-dictionary.aspx
Dictionary不是线程安全的,如果在多线程情况下,有线程在读的时候,另外一个线程写,就有可能导致死锁,进而造成cpu100%
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,