public Task Prepare() { Task.Factory.StartNew(async() => { IsolatedState isolatedState = new IsolatedState(); for (int i = 0; i < NumberOfProducers; i++) { var taskId = i; _executors.Add(RegisterSingleCommand(_workerBlock, isolatedState, taskId)); await WaitingSimulation(); } }); return(Task.CompletedTask); }
protected abstract Task RegisterSingleCommand(ActionBlock <SimpleCommand> workerBlock, IsolatedState isolatedState, int taskId);
public SimpleCommand(IsolatedState isolatedState) { _taskCompletionSource = new TaskCompletionSource <int>(); _isolatedState = isolatedState; }
protected override async Task RegisterSingleCommand(ActionBlock <SimpleCommand> workerBlock, IsolatedState isolatedState, int taskId) { Console.WriteLine($"\t\tTask {taskId:000}\tA"); var simpleCommand = new SimpleCommand(isolatedState); if (!workerBlock.Post(simpleCommand)) { simpleCommand.Abort(); } Console.WriteLine($"\t\tTask {taskId:000}\tB"); var updatedValue = await simpleCommand.UpdatedValue; Console.WriteLine($"\t\tTask {taskId:000}\tC\tupdatedValue={updatedValue}"); }