Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop polling in SignalR?

Tags:

signalr

Is there any way to stop polling server in SignalR? I want to stop polling server if error occurs. Polling hubs is started with $.connection.hub.start(), so I assumed that it could be stopped with $.connection.hub.stop() or something like that. But it doesn't seem to work, polling continues even after calling stop(). Is there another way to stop pollling?

<script type="text/javascript">

 var chatHub = $.connection.chatHub;
 var connection = $.connection.hub;

chatHub.addMessage = function (message) {
      $('#messages').append('<li>' + message + '</li>');
    };

connection.error(function (error) {
 $('#messages').append('<li>' + "error connecting: closing connnection" + '</li>');
    connection.stop(); //This doesn't seem to work   
        });

connection.start();

</script>
like image 587
nivkovic Avatar asked Nov 29 '11 13:11

nivkovic


People also ask

How do I stop SignalR?

A SignalR connection can end in any of the following ways: If the client calls the Stop method, a stop message is sent to the server, and both client and server end the SignalR connection immediately.

What is SignalR long polling?

SignalR is a Microsoft framework specifically designed to facilitate real-time client/server communication. It provides an effective implementation of long polling that doesn't have a deep impact on the server, and at the same time ensures that clients are appropriately updated about what's going on remotely.

How do I set SignalR connection timeout?

Timeout configuration for SignalR can be set in Application_Start method of Global class in Global. asax. cs file. // Wait a maximum of 30 minutes after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.


1 Answers

If you're using hubs you can stop the hub's connection:

$.connection.hub.stop();
like image 77
davidfowl Avatar answered Nov 16 '22 07:11

davidfowl