如果我有一个在工作线程上运行的任务并且当它发现问题时,是否可以暂停并等待用户干预然后再继续?
例如,假设我有这样的事情:
async void btnStartTask_Click(object sender, EventArgs e)
{
await Task.Run(() => LongRunningTask());
}
// CPU-bound
bool LongRunningTask()
{
// Establish some connection here.
// Do some work here.
List<Foo> incorrectValues = GetIncorrectValuesFromAbove();
if (incorrectValues.Count > 0)
{
// Here, I want to present the "incorrect values" to the user (on the UI thread)
// and let them select whether to modify a value, ignore it, or abort.
var confirmedValues = WaitForUserInput(incorrectValues);
}
// Continue processing.
}
Run Code Online (Sandbox Code Playgroud)
是否可以WaitForUserInput()用在 …