V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
bthulu
V2EX  ›  .NET

ConcurrentDictionary 有什么办法确保一次添加多项的原子性吗?

  •  
  •   bthulu · Oct 2, 2022 · 2187 views
    This topic created in 1309 days ago, the information mentioned may be changed or developed.
        private readonly ConcurrentDictionary<int, string> Dict = new();
    
        // 如何保证原子性?
        public void AddMore(IEnumerable<(int, string)> items)
        {
            foreach ((int key, string? value) in items)
            {
                Dict.TryAdd(key, value);
            }
        }
    
    liuhan907
        1
    liuhan907  
       Oct 3, 2022
    没有办法。换个常规字典自己 lock 吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:59 · PVG 01:59 · LAX 10:59 · JFK 13:59
    ♥ Do have faith in what you're doing.