locked
Count visitor online wrong RRS feed

  • Question

  • User-1764397001 posted

    This is my Code :

    Startup

    Imports Microsoft.Owin
    Imports Owin
    
    Public Class Startup
        Public Sub Configuration(app As IAppBuilder)
            app.MapSignalR()
        End Sub
    End Class

    MyHub

    Imports Microsoft.AspNet.SignalR
    Imports Microsoft.AspNet.SignalR.Hubs
    <HubName("OnlineHub")>
    Public Class OnlineHub
        Inherits Hub
        Shared _hitCount As Integer = 0
    
        Public Sub RecordHit()
            _hitCount += 1
            Clients.All.onRecordHit(_hitCount)
        End Sub
    
        Public Overrides Function OnDisconnected(stopCalled As Boolean) As System.Threading.Tasks.Task
            _hitCount -= 1
            Clients.All.onRecordHit(_hitCount)
            Return MyBase.OnDisconnected(stopCalled)
        End Function
    End Class
    


    My SCript

    <script type="text/javascript">
            $(function () {
                
                var connection = $.hubConnection();
                var hub = connection.createHubProxy("OnlineHub");
                hub.on("onRecordHit", function (hitCount) {
                    $('#pagehits').text(hitCount);
                });
                connection.start(function () {
                    hub.invoke('RecordHit');
                });
            })
        </script>

    I do not know why ?
    In a time to use, it miscalculated.
    You can see the image below. Negative Number

    Please help me

    Tuesday, January 26, 2016 5:10 PM

Answers

All replies