草庐IT

parallel-collections

全部标签

c# - 奇怪的 "Collection was modified after the enumerator was instantiated"异常

也许有人可以为我指出正确的方向,因为我对此一头雾水。我有一个函数可以简单地打印出类的LinkedList:LinkedListcomponents=newLinkedList();...privatevoidPrintComponentList(){Console.WriteLine("---ComponentList:"+components.Count+"entries---");foreach(Componentcincomponents){Console.WriteLine(c);}Console.WriteLine("------");}Component对象实际上有一个自定

c# - 嵌套的 Parallel.For() 循环速度和性能

我有一个嵌套的for循环。我用Parallel.For()替换了第一个For,计算速度提高了。我的问题是关于用Parallel.For()替换第二个for(内部)。会提高速度吗?或者没有区别?还是会变慢?编辑:由于内核不是无限的(通常有2到8个内核),因此内部循环是并行运行的。因此,如果我用Parallel.For()更改内部for,它会再次并行运行。但我不确定它如何改变性能和速度。 最佳答案 来自“太细粒度,太粗粒度”小节,“反模式”部分在"Patternsofparallelprogramming"通过.NETparallelc

c# - 避免 InvalidOperationException : Collection was modified? 的最佳实践

我经常需要这样的东西:foreach(Linelineinlines){if(line.FullfilsCertainConditions()){lines.Remove(line)}}这不起作用,因为我总是得到一个InvalidOperationException,因为Enumerator在循环期间被更改了。所以我将所有此类循环更改为以下内容:Listremove=newList();foreach(Linelineinlines){if(line.FullfilsCertainConditions()){remove.Add(line)}}foreach(Linelineinrem

c# - 嵌套的 Parallel.ForEach 循环在同一个列表中?

我需要并行化一个对列表中的元素进行详尽的成对比较的方法。串行实现很简单:foreach(varelement1inlist)foreach(varelement2inlist)foo(element1,element2);在这种情况下,foo不会改变element1或element2的状态。我知道简单地执行嵌套的Parallel.ForEach语句是不安全的:Parallel.ForEach(list,delegate(Aelement1){Parallel.ForEach(list,delegate(Aelement2){foo(element1,element2);});});使用

c# - Parallel.Foreach 给出错误 "Index was outside the bounds of the array "

我在parallel.foreach中遇到了一些问题,即“索引超出了数组的范围”。我附上了parallel.foreach的一些代码以及崩溃的地方。varlstFRItems=session.CreateCriteria().Add(Restrictions.Eq("TSCEnterprise.FEnterpriseID",EnterpriseId)).AddOrder(Order.Asc("FName")).List();ListlstItemAccount=newList();varListAccounts=session.CreateCriteria().List();//lst

c# - "Collection was of a fixed size"带有 POCO 的 EF4 异常

我将EF4与WCF和POCO结合使用。我删除了POCO实体中的所有虚拟关键字。我有Employee和Team实体,两者之间的关系是1:N,意味着一名员工只能分配到一个团队。我想在现有团队中添加新员工。以下代码在客户端。privatevoidbtnAdd_Click(objectsender,RoutedEventArgse){TeamteamFromDb=ServiceProxy.GetService.GetTeamById(181);EmployeenewEmp=newEmployee{UserName="username"};newEmp.Team=teamFromDb;Servi

c# - DDD : entity's collection and repositories

假设我有publicclassProduct:Entity{publicIListItems{get;set;}}假设我想找到一个最大的项目...我可以添加方法Product.GetMaxItemSmth()并使用Linq(fromiinItemsselecti.smth).Max())或使用手动循环或其他方式。现在,问题是这会将整个集合加载到内存中。正确的解决方案是进行特定的数据库查询,但域实体无权访问存储库,对吧?所以要么我做productRepository.GetMaxItemSmth(product)(这很丑,不是吗?),或者即使实体可以访问存储库,我也使用来自实体的IPro

c# - System.Collections.Generic.List 中的某项在什么情况下不会被删除成功?

在什么情况下System.Collections.Generic.List中的item不会被成功移除?来自http://msdn.microsoft.com/en-us/library/cd666k3e.aspx:trueifitemissuccessfullyremoved;otherwise,false.ThismethodalsoreturnsfalseifitemwasnotfoundintheList(OfT).他们表达它的方式让我认为对List(OfT)中找到的项目的删除操作实际上可能会失败,因此这个问题。 最佳答案 查

c# - Parallel.Foreach 与正常 ForEach 一样快/慢

更新:我使用线程在内核数量(在我的案例中为8个)中拆分循环,并且整个循环在不到1秒的时间内完成。所以问题不在于,使用线程操作不会更快。为什么ParralelExtension在这种情况下会失败?大家好。我想用Parrallel.Foreach转换我的ForEach。问题是,并行化几乎没有给我带来任何好处。原文:foreach(Entities.Buchungbuchunginbuchungen){Int32categoryID=manager.GetCategoryID(newRegelengine.Booking(buchung));//Average4msbuchung.Categ

C# 应用程序设置 : Is there a easy way to put a collection into <appSetting>

我试过了和System.Configuration.ConfigurationManager.AppSettings.GetValues("List");但我只得到最后一个成员。我怎样才能轻松解决这个问题? 最佳答案 我处理过类似的问题,我是用这段代码解决的。希望这对您的问题有所帮助。在这种情况下,列表(类似于我的URLSection)将在web.config中有一个完整的配置部分,然后您可以从该部分获取所有值。我为此创建了三个类:ConfigElement、ConfigElementCollection、WebConfigSect