相关疑难解决方法(0)

并发字典正确用法

我是否正确地认为这是正确使用并发字典

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;
Run Code Online (Sandbox Code Playgroud)

我没有锁等,只是更新字典中的值,即使多个线程可能尝试做同样的事情.

.net c# concurrency multithreading .net-4.0

77
推荐指数
1
解决办法
7万
查看次数

标签 统计

.net ×1

.net-4.0 ×1

c# ×1

concurrency ×1

multithreading ×1