Mercurial > hg > Database > Christie-sharp
view datagear/WaitList.cs @ 19:c9d1a5a79254
fix ConcurrentQueue
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Dec 2020 17:48:03 +0900 |
parents | |
children | 3aaa77e12493 |
line wrap: on
line source
using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using Christie_net.datagear.command; namespace Christie_net.datagear { public class WaitList { private Dictionary<string, BlockingCollection<Command>> waitlist = new Dictionary<string, BlockingCollection<Command>>(); private object syncObject = new object(); public void add(Command cm) { lock (syncObject) { if (waitlist.ContainsKey(cm.key)) { waitlist[cm.key].TryAdd(cm); } else { BlockingCollection<Command> queue = new BlockingCollection<Command>(); queue.TryAdd(cm); waitlist.Add(cm.key, queue); } } } public bool ContainsKey(string key) { lock (syncObject) { return waitlist.ContainsKey(key); } } } }