Search code examples
c#coding-stylesignalr

Should I call async SignalR hub methods MethodNameAsync(), or not


Usually in C#, it is a good practice to call asynchronious methods MethodNameAsync(), to make it clear for the user, that this method runs asynchronious. However, everything that is related to SignalR and is async doesn't carry async in it's name. The OnConnected method, for example, is async, but it's not OnConnectedAsync().

To make a long story short: Would you recommend to call any hub method public async Task MyMethodAsync(), or simply public async Task MyMethod()? Is the asynchronicity of the method of any mean for the end user of my hub?


Solution

  • Do not suffix them with Async as this would leak an implementation detail to your users.

    If you are enforcing The Async suffix through analyzers in your project, you can put a [SuppressMessage(..., Justification = "RPC methods should not be suffixed with 'Async'."] Attribute to your methods.