public override Image CaptureUrl(string baseUrl, TimeSpan timeOut) { IWorker currentWorker = null; bool workerCompromise = false; try { // Wait for an available worker currentWorker = _workerPool.BlockingPeek(); // Bound all the request parameters to RemoteTask var remoteTask = CreateTask(baseUrl, timeOut); var taskResult = currentWorker.PerformTask(remoteTask); // When taskResult returns null, means that remoteworker is compromised and cannot be reused if (taskResult == null) { workerCompromise = true; throw new CaptureEngineException("RemoteWorker has shutdown", CaptureEngineState.InternalError); } if (taskResult.Error) { throw taskResult.Exception; } using (var memoryStream = new MemoryStream(taskResult.PayLoad)) { return(Image.FromStream(memoryStream)); } } finally { if (currentWorker != null) { _workerPool.Return(currentWorker, workerCompromise); } } }