问题
I'm using SignalR to transferring commands from client to server without refreshing the page. When the client enter some of my web pages, I'm starting a new hub connection. Like this:
var hub = $.connection.siteControllerHub;
$.connection.hub.start();
This "start()" function takes some time (+-5 seconds). mean while, the page is already finished loading and the user start using my UI. SingalR cannot serve the user, until it's finish loading the connection.
I'm know that I'm can use the async approach with the done() register:
$.connection.siteControllerHub.start().done(function () {
// On finish loading...
});
But this kind of operations is not suitable for me, since if I'm using this - I'm need to disable the UI until this event happens. And this not cool at all.
I'm prefer that loading of the page will takes longer but when it's done, everything will be ready for use.
What do you think? How do you recommend to implement it? Thank you.
回答1:
5 seconds is not normal. Anyway you can queue the messages and when done
is called take the queued messages and send to server. Look here for example
https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/blob/master/SignalR.EventAggregatorProxy.Client.JS/jquery.signalR.eventAggregator.js#L173
来源:https://stackoverflow.com/questions/26369495/hub-start-wait-for-finish