// /** // * File: TaskQueue.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using ln.collections; using System.Linq; namespace ln.threading { public class TaskQueue { BTreeValueList queue = new BTreeValueList(); public TaskQueue() { } public bool Empty => queue.Keys.Count() == 0; public void Enqueue(Action action) => Enqueue(0, action); public void Enqueue(int priority,Action action) { lock (queue) { queue.TryRemove(priority, action); queue.Add(priority, action); } } public Action Dequeue() { lock (queue) { return queue.Shift(); } } } }