admin管理员组

文章数量:1289911

I have a class with an extension method for signal-r messages in C#:

public static class SignalMethods
{
    public static Task SendMessageAsync(this IHubContext<MyHub> hub, IEnumerable<string> users, string method, string origin, string message)
    {
        return hub.Clients.Users(users).SendAsync(method, new MyMessage(origin, message));
    }

    public static void SendMessage(this IHubContext<MyHub> hub, IEnumerable<string> users, string method, string origin, string message)
    {
        hub.Clients.Users(users).SendAsync(method, new MyMessage(origin, message));
    }
}

Does it affect how it behaves (or does it affect the performance) if I call one method or the other from a non-async service in my application? Below are the 2 possible calls

_hubContext.SendMessageAsync(users, "my method async", "me", "test 1");
_hubContext.SendMessage(users, "my method", "me", "test 2");

I presume I could also call SendMessageAsync awaiting the call like this:

await _hubContext.SendMessageAsync(users, "my method async", "me", "test 1");

What's the recommended approach?

本文标签: csignalr sync vs asyncStack Overflow