Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

c# - Is there a way of setting a Task driven via TaskCompletionSource to Status 'Running'?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...