问题描述
我有大约1 milions项的字典。我不断循环扔dictionnary:
I have a dictionary with around 1 milions items. I am constantly looping throw the dictionnary :
public void DoAllJobs()
{
foreach (KeyValuePair<uint, BusinessObject> p in _dictionnary)
{
if(p.Value.MustDoJob)
p.Value.DoJob();
}
}
执行是有点长,约600毫秒,我想deacrese它。这里是约束上:
The execution is a bit long, around 600 ms, I would like to deacrese it. Here is the contraints :
- MustDoJob值大多停留在同一beetween两次调用DoAllJobs()
- 的MustDoJob值==虚假
- 从时间到时间的60%-70%MustDoJob 200000双改变。
- 若干p.Value。 DoJob()不能在同一时间(COM对象调用)
- 在这里,我不需要_dictionnary的重要组成部分客体,但我真的需要在别的地方 $ b来计算$ b
- MustDoJob values mostly stay the same beetween two calls to DoAllJobs()
- 60-70% of the MustDoJob values == false
- From time to times MustDoJob change for 200 000 pairs.
- Some p.Value.DoJob() can not be computed at the same time (COM object call)
- Here, I do not need the key part of the _dictionnary objet but I really do need it somewhere else
我要做到以下几点:
- 并行,但我不知道将是有效的,由于4
- 自排序1.和2. dictionnary(并停止想我找到的第一个MustDoJob ==假的),但我想知道什么3 。会导致
我没有实现任何以前的想法,因为它可能是很多工作,我想调查其他选项之前。所以...任何想法?
I did not implement any of the previous ideas since it could be a lot of job and I would like to investigate others options before. So...any ideas ?
推荐答案
我的建议是,你的业务对象可能引发一个事件来表明它需要做任务时 MustDoJob
为真,您可以订阅该事件,并引用存储在一个简单的列表中的那些对象,然后处理该列表中的内容时, DoAllJobs()
方法被称为
What I would suggest is that your business object could raise an event to indicate that it needs to do a job when MustDoJob
becomes true and you can subscribe to that event and store references to those objects in a simple list and then process the contents of that list when the DoAllJobs()
method is called
这篇关于C#字典环Enhancment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!