Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ConcurrentDictionary<int,long> myDic = new ConcurrentDictionary<int,long>();
- //Main thread at program startup
- for(int i = 0; i < 4; i++)
- {
- myDic.Add(i, 0);
- }
- //Seperate threads use this to update a value
- myDic[InputID] = newLongValue;
- ConcurrentDictionary<TKey, TValue>.AddOrUpdate Method (TKey, Func<TKey, TValue>, Func<TKey, TValue, TValue>);
- results.AddOrUpdate(
- Id,
- id => new DbResult() {
- Id = id,
- Value = row.Value,
- Rank = 1
- },
- (id, v) =>
- {
- v.Rank++;
- return v;
- });
- Parallel.For(0, 4, i =>
- {
- myDic.TryAdd(i, 0);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement