bthulu
V2EX  ›  .NET

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

  •  
  •   bthulu · Oct 2, 2022 · 2232 views
    This topic created in 1328 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   ·   959 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:25 · PVG 03:25 · LAX 12:25 · JFK 15:25
    ♥ Do have faith in what you're doing.