/// <summary> /// Pick a task for execution and sets specified <paramref name="worker"/> for it. /// </summary> /// <param name="worker"> /// An instance of <see cref="IWorkerChannel"/> that specifies communication channel for task's executor /// </param> /// <param name="timeout"> /// Operation timeout. /// </param> /// <returns> /// An instance of <see cref="Task"/> that is ready for execution. /// </returns> /// <remarks> /// <para> /// This method blocks calling thread until a task is picked. /// </para> /// <para> /// After picking a task, task queue ensures that the picked task will not be picked anymore. /// </para> /// </remarks> public Task PickTask(IWorkerChannel worker, TimeSpan timeout) { Task task; try { lock (task = pendingTasks.Dequeue(timeout)) { task.State = TaskState.Processing; task.Worker = worker; return task; } } catch (TimeoutException) { return null; } }
/// <summary> /// Pick a task for execution and sets specified <paramref name="worker"/> for it. /// </summary> /// <param name="worker"> /// An instance of <see cref="IWorkerChannel"/> that specifies communication channel for task's executor /// </param> /// <returns> /// An instance of <see cref="Task"/> that is ready for execution. /// </returns> /// <remarks> /// <para> /// This method blocks calling thread until a task is picked. /// </para> /// <para> /// After picking a task, task queue ensures that the picked task will not be picked anymore. /// </para> /// </remarks> public Task PickTask(IWorkerChannel worker) { Contract.Requires(worker != null); throw new NotImplementedException(); }
/// <summary> /// Pick a task for execution and sets specified <paramref name="worker"/> for it. /// </summary> /// <param name="worker"> /// An instance of <see cref="IWorkerChannel"/> that specifies communication channel for task's executor /// </param> /// <returns> /// An instance of <see cref="Task"/> that is ready for execution. /// </returns> /// <remarks> /// <para> /// This method blocks calling thread until a task is picked. /// </para> /// <para> /// After picking a task, task queue ensures that the picked task will not be picked anymore. /// </para> /// </remarks> public Task PickTask(IWorkerChannel worker) { Task task; lock (task = pendingTasks.Dequeue()) { task.State = TaskState.Processing; task.Worker = worker; return task; } }