当我们处理异步任务时,任务由多个方法调用(可能是其他类)组成,而这些方法调用又由进一步的方法调用组成。我们可以称它为一棵树。是否所有方法都必须是异步任务类型才能使原始任务真正表现出异步? 答案是否适用于其他类似语言(主要是 Java)的任何类型的后台任务? (在 C# 中,一旦我在这棵树中某处的方法之一进入无限循环(谈论长时间运行的任务!),但遗憾的是,原始异步任务的 isRunning 属性返回 false。)
最佳答案
Do all methods have to be of type async task for the original task to truly behave async?
为了异步运行,async
方法必须有一个 await
语句用于尚未完成的操作。
我想我的async
intro blog post会对你有所帮助。
Would the answer be true for any kind of background task of other similar languages, mostly Java as well?
是的。
sadly, the original async task's isRunning property returned false
我假设您的意思是 TaskStatus
不是 TaskStatus.Running
。 This is normal and expected ,因为异步任务是 Promise Tasks, not Delegate Tasks (有关详细信息,请参阅我的博客)。
关于C# 异步任务 : do all participating methods have to be async as well?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39365868/