Is it good practice to call static methods in the Hub class? and if so should I put a lock around the static method? My goal is to send a message from to the client based on an event that is fired outside the hub class
asynchronously.
Is it good practice to call static methods in the Hub class? and if so should I put a lock around the static method? My goal is to send a message from to the client based on an event that is fired outside the hub class
asynchronously.
Hi MrJRema,
Thanks for your post.
If necessary, you can use the signalR static method to send message to clients. However, you should use the
GlobalHost.ConnectionManager.GetHubContext to access the context of connection like below.
public static void StaticTest()
{
var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
context.Clients.All.addMessage("yourmessage");
}
None
0 Points
5 Posts
Is it good practice to call statice methods in the Hub class
Jul 14, 2014 04:06 PM|MrJRema|LINK
Is it good practice to call static methods in the Hub class? and if so should I put a lock around the static method? My goal is to send a message from to the client based on an event that is fired outside the hub class asynchronously.
async task signalr
All-Star
30411 Points
3628 Posts
Re: Is it good practice to call statice methods in the Hub class
Jul 24, 2014 05:06 AM|Fuxiang Zhang - MSFT|LINK
Hi MrJRema,
Thanks for your post.
If necessary, you can use the signalR static method to send message to clients. However, you should use the
GlobalHost.ConnectionManager.GetHubContext to access the context of connection like below.
public static void StaticTest() { var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); context.Clients.All.addMessage("yourmessage"); }
http://stackoverflow.com/questions/7634255/calling-signalr-hub-clients-from-elsewhere-in-system
Besides, I think we need not set a lock to the static method that because every client can call the method independently.
Thanks.
Best Regards!
async task signalr