My original method looks like:
string DoSomeWork();
Method DoSomeWork
starts some work on another thread and returns execution ID (just random string). Later on I can query results by the returned execution ID. Main point is to make execution ID available before job will complete.
Now I want to change signature to return Task
, so user can wait if he want to.
Task DoSomeWork();
At the same time I still need to return execution ID (for tracing purposes for example) and I see a few options. First, use an out
parameter, second, return tuple with both execution ID and task (in C# this looks like not a best option), and third, about which I actually want to ask.
What if I create a class that derives Task
:
public class ExtendedTask : Task
{
public string ExecutionID {get; set;}
}
Does this look ok? Or is it better to decide other options?
P.S. In BCL there are some classes derived from Task
.
UPDATE, seems I was not able to define this clear enough. But I need access to ExecutionID before the job completes so I cannot use Task.Result
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…