是否有驱动设置通过TaskCompletionSource到状态“正在运行”任务的一种方式? [英] Is there a way of setting a Task driven via TaskCompletionSource to Status 'Running'?
问题描述
我用 TaskCompletionSource
来提供,推动任务
的一个实例。我希望能够将工作
来状态运行
来表示任务......运行不过,我看不到的方式通过 TaskCompletionSource
来实现这一目标。
I'm using TaskCompletionSource
to provide and drive an instance of Task
. I would like to be able to set the Task
to status Running
to indicate that the task is... 'running' however I can't see a way to achieve this via TaskCompletionSource
.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
没有。没有一种方式。
No. There isn't a way.
无论你是否喜欢我的答案,但是,它是正确的。 : - )
Whether or not you like my answer, however, it is the correct one. :-)
下面是我的看法,并试图帮助你感觉好
The following is my opinion, and an attempt to help you feel better.
任务。状态有几个规定,只设置和有用的任务是计划任务。从TaskCompletionSource任务没有计划任务。因此WaitingToRun,跑步等的概念并不适用于传统的计划任务感。如果你确实有设置这些能力,你必须在什么语义应用到这些值,这可能与其他人如何解释这些冲突做出决定。
Task.Status has several states that are only set and useful when the task is a scheduled task. Tasks from TaskCompletionSource are not scheduled tasks. The concept of WaitingToRun, Running, etc. are therefore not applicable in the traditional scheduled task sense. If you did have the ability to set these, you'd have to decide on what semantics to apply to these values, which may conflict with how others interpret them.
最后,我不认为你的代码应该永远做基于这些中间状态反正任何决定。这样做听起来像一个代码味道。
Ultimately, I don't think your code should ever make any decisions based on these intermediate states anyway. Doing so sounds like a "code smell".
这篇关于是否有驱动设置通过TaskCompletionSource到状态“正在运行”任务的一种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!