Concurrent Dictionary Correct Usage

前端 未结 5 927
名媛妹妹
名媛妹妹 2020-12-13 05:27

Am I right in thinking this is the correct use of a Concurrent Dictionary

private ConcurrentDictionary myDic = new ConcurrentDictionary

        
5条回答
  •  有刺的猬
    2020-12-13 06:02

    Just a note: Does not justify using a ConcurrentDicitonary object with a linear loop, making it underutilized. The best alternative is to follow the recommendations of the Microsoft Documentation, as mentioned by Oded using Parallelism, according to the example below:

    Parallel.For(0, 4, i => 
    {
       myDic.TryAdd(i, 0);
    });
    

提交回复
热议问题