/// <summary> /// Checks if the queue exists, if it doesn't it creates a new queue in <see cref="QueueTracker"/> and then starts a separate <see cref="Thread"/> running <see cref="DequeuAndProcessCommand"/>. /// </summary> /// <param name="queueName">The name of the queue.</param> protected virtual void CreateQueueAndAttachListenerIfNotExist(string queueName) { if (!QueueTracker.ContainsKey(queueName)) { QueueTrackerLock.EnterWriteLock(); try { if (!QueueTracker.ContainsKey(queueName)) { QueueTracker.TryAdd(queueName, new ConcurrentQueue <ICommand <TAuthenticationToken> >()); new Thread(() => { Thread.CurrentThread.Name = queueName; DequeuAndProcessCommand(queueName); }).Start(); } } catch (Exception exception) { Logger.LogError(string.Format("Processing a request to start a thread for the queue '{0}' failed.", queueName), exception: exception); } finally { QueueTrackerLock.ExitWriteLock(); } } }