我正在尝试防止任务在第一部分失败后继续进行。
我的代码如下:
现在,如果 openConnection() 进入 catch 块,就不应该执行 listenForNumber()。
我尝试使用
谢谢。
我的代码如下:
Task listener = Task.Factory.StartNew(openConnection).ContinueWith((t) => listenForNumber());
void openConnection()
{
try
{
//stuff
}
catch
{
//morestuff
}
}
void listenForNumber()
{
//even more stuff
}
现在,如果 openConnection() 进入 catch 块,就不应该执行 listenForNumber()。
我尝试使用
ContinueWith((t) => listenForNumber(),TaskContinuationOptions.NotOnFaulted);
,但没有成功,需要帮助吗? :(谢谢。