public CommandProcessor(ICommandProcessingStrategy processingStrategy, ICommandQueue commandQueue) { _processingStrategy = processingStrategy; _commandQueue = commandQueue; _cancellationTokenSource = new CancellationTokenSource(); var token = _cancellationTokenSource.Token; var task = new Task( () => { while (!token.IsCancellationRequested) { var cmd = _commandQueue.Dequeue(); while (cmd != null) { _processingStrategy.ProcessCommand(cmd.Execute); cmd = commandQueue.Dequeue(); } Thread.Sleep(100); } }, token, TaskCreationOptions.LongRunning); task.Start(); }