using System.Collections.Generic; using System; using System.Collections.Generic; namespace TellmePdmsPluging.Core { public static class SafeQueue { private static readonly object _sync = new object(); private static Queue _queue; public static void Init() { if (_queue != null) { return; } lock (_sync) { if (_queue == null) { _queue = new Queue(); } } } public static void Enqueue(ICommand command) { if (command == null) { return; } Init(); lock (_sync) { _queue.Enqueue(command); } } public static bool TryDequeue(out ICommand command) { Init(); lock (_sync) { if (_queue.Count > 0) { command = _queue.Dequeue(); return true; } } command = null; return false; } } public interface IResultCommand : ICommand { object Result { get; } Exception Error { get; } bool IsCompleted { get; } } }