views:

60

answers:

3

APM uses BeginXXX/EndXX pairs and the Event-based Asynchronous Pattern (EAP) uses XXXAsync and XXXCompleted pairs, but I haven't seen anything standard on how to name methods that return a task.

I have been using XXXTask:

Data GetData() 
Task<Data> GetDataTask()

but was wondering if a more standard approach has developed

A: 

You may consider to provide a Property instead of a GetXXX-Method, which is more usual in C#. You could then write

Task<Data> DataTask { get; set; } //auto-implemented
Simon
I think this is somewhat orthogonal to the Task version - GetData() being a method instead of a property would be the original choice, and given that it's heavyweight enough to create an async version, it sounds like that's the right choice :) The *Task version also being a method certainly makes sense and matches the pattern done in the ParallelExtensionsExtras library (although one could argue the choice wasn't there since there is no support for extension properties :)Methods vs. properties guidelines for others that run across this:http://msdn.microsoft.com/en-us/library/ms229054.aspx
James Manning
Great article... thanks
Simon
A: 

Not sure what you are doing, but you could wrap tasks into a seperate class.

So instead of having GetPrintTask you'll have MyCustomTasksClass.GetPrint

vikp
+1  A: 

I'd recommend using the patterns in the ParallelExtensionsExtras library since that's done by the same team that made the TPL in the first place :)

http://blogs.msdn.com/b/pfxteam/archive/2010/05/04/10007557.aspx

Their pattern seems to be the same as yours: [SyncAction]Task for the method that does SyncAction async via a Task (which is returned) - DownloadDataTask, SendTask, etc.

James Manning
Accepted, not for agreeing with me, but for providing the reference. Thanks!
Karg
I have to admit, the naming actually seems a little odd to me in terms of the goal that method names should read like an action - BeginFoo, EndFoo are pretty clear (as names), and FooAsync is even decent IMHO as async seems to clearly be an adverb. However, FooTask is actually kind of odd to me in that the 'foo' verb has a noun just tacked onto the end. IMHO it is then confusing, as, for instance "SendTask" as a method name makes me thing it's something that is going to Send a Task. I'm not sure "FooAsTask" or "FooAsyncAsTask" are actually better, though - so theirs is fine with me. :)
James Manning