Код: Выделить всё
this.backgroundTcs = new TaskCompletionSource();
bool quit = false;
while (!quit) {
Task inputTask = Console.In.ReadLineAsync();
await Task.WhenAny(inputTask, backgroundTcs.Task);
Console.WriteLine($"Status: {inputTask.Status}, {backgroundTcs.Task.Status}");
// do something with either of the tasks, depending on their IsCompleted properties
if (inputTask.IsCompletedSuccessfully) {
quit = DispatchDebuggerCommand(inputTask.Result);
}
}
Код: Выделить всё
void OnBreakInstruction() {
backroundTcs.SetResult(); // This does get executed (from the background thread)
}
Как мне написать код, чтобы я мог ожидать либо ввода командной строки из консоли, либо завершения задачи?
Подробнее здесь: https://stackoverflow.com/questions/798 ... rallel-wit
Мобильная версия