Reputation: 1647
If an API has a synchronous method T DoSomething<T>();
, what is the naming convention for the corresponding asynchronous method if it returns Task<T>
?
Task<T> DoSomethingTask<T>();
or
Task<T> DoSomethingAsync<T>();
or something else?
Upvotes: 7
Views: 1161
Reputation: 58980
From what I've seen in C# 5 / .NET 4.5, the preferred name is DoSomethingTaskAsync
or DoSomethingAsync
For example, the WebClient class in .NET 4.5 has methods like DownloadFileTaskAsync
, because it already had a method named DownloadFileAsync
, so I assume the use of TaskAsync
over Async
is to maintain backwards compatibility.
Upvotes: 7
Reputation: 2721
If you are talking about an async
or await
method, then from MSDN:
By convention, the suffix "Async" is added to the names of methods that are modified by the Async or async modifier.
...
Exceptions to the convention can be made where an event, base class, or interface contract suggests a different name. For example, the names of common event handlers, such as button1_Click, are best not renamed.
Upvotes: 8