Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. private ConcurrentDictionary<int,long> myDic = new ConcurrentDictionary<int,long>();
  2.  
  3. //Main thread at program startup
  4.  
  5. for(int i = 0; i < 4; i++)
  6. {
  7. myDic.Add(i, 0);
  8. }
  9.  
  10. //Seperate threads use this to update a value
  11.  
  12. myDic[InputID] = newLongValue;
  13.  
  14. ConcurrentDictionary<TKey, TValue>.AddOrUpdate Method (TKey, Func<TKey, TValue>, Func<TKey, TValue, TValue>);
  15.  
  16. results.AddOrUpdate(
  17. Id,
  18. id => new DbResult() {
  19. Id = id,
  20. Value = row.Value,
  21. Rank = 1
  22. },
  23. (id, v) =>
  24. {
  25. v.Rank++;
  26. return v;
  27. });
  28.  
  29. Parallel.For(0, 4, i =>
  30. {
  31. myDic.TryAdd(i, 0);
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement