What is the accepted pattern for naming methods that return Tasks?
开发者_Python百科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
For C# 5.0 (with .NET 4.5), the naming convention is XXXAsync for task returning methods.
If there already exists a method with this naming (for instance, on the WebClient already has a DownloadDataAsync method that implements the EAP pattern), then the Task returning async method should be named XXXTaskAsync.
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 :)
Link
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.
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
精彩评论