在其他延续未执行时执行 ContinueWith
executing ContinueWith when other continuations have not executed
给出这样的东西:
.ContinueWith((_, o) => this.Foo(), null, TaskContinuationOptions.OnlyOnRanToCompletion)
.ContinueWith((_, o) => this.Bar(), null, TaskContinuationOptions.OnlyOnFaulted)
.ContinueWith((_, o) => this.AnythingElse(), null, TaskContinuationOptions.?
有没有什么方法可以构造一个继续执行 AnythingElse
当其他继续未执行时?
我想捕获所有其他可能的终止,但前提是上面的前两个延续之一尚未执行。
使用 OnlyOnCancelled
因为这是唯一的其他情况。
你也可以使用一个统一的延续,根据任务状态决定做什么。我认为这是最干净的方法,因为它会生成顺序查找代码。
给出这样的东西:
.ContinueWith((_, o) => this.Foo(), null, TaskContinuationOptions.OnlyOnRanToCompletion)
.ContinueWith((_, o) => this.Bar(), null, TaskContinuationOptions.OnlyOnFaulted)
.ContinueWith((_, o) => this.AnythingElse(), null, TaskContinuationOptions.?
有没有什么方法可以构造一个继续执行 AnythingElse
当其他继续未执行时?
我想捕获所有其他可能的终止,但前提是上面的前两个延续之一尚未执行。
使用 OnlyOnCancelled
因为这是唯一的其他情况。
你也可以使用一个统一的延续,根据任务状态决定做什么。我认为这是最干净的方法,因为它会生成顺序查找代码。