Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim _hubConnection As HubConnection
- Dim _myHubProxy As IHubProxy
- Async Function InitiateConnection() As Task
- _hubConnection = New HubConnection("http://localhost:4848")
- AddHandler _hubConnection.Closed,
- Sub()
- Console.BackgroundColor = ConsoleColor.White
- Console.ForegroundColor = ConsoleColor.Red
- Console.WriteLine("CONNECTION STATE: CLOSED")
- Console.ResetColor()
- End Sub
- AddHandler _hubConnection.[Error], Sub(e)
- Console.BackgroundColor = ConsoleColor.Red
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("Hub connection error: " & e.ToString())
- Console.ResetColor()
- End Sub
- AddHandler _hubConnection.StateChanged, Sub(state)
- Console.BackgroundColor = ConsoleColor.DarkYellow
- Console.ForegroundColor = ConsoleColor.Black
- Console.WriteLine("Connection State Changed From {0} To {1}", state.OldState, state.NewState)
- Console.ResetColor()
- If state.NewState = ConnectionState.Disconnected Then
- Console.BackgroundColor = ConsoleColor.Blue
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("Reconnecting in 500 ms")
- Console.ResetColor()
- Thread.Sleep(500)
- _hubConnection.Start() ' Will never reconnect. Workaround: Recreate connection Task.Run(Sub() hubConnection.Start().Wait()) _hubConnection.Start(); ' Will never reconnect. Workaround: Recreate connection CreateConnection().Start();
- ElseIf state.NewState = ConnectionState.Connected Then
- Console.BackgroundColor = ConsoleColor.Green
- Console.ForegroundColor = ConsoleColor.Black
- Console.WriteLine("CONNECTION STATE: CONNECTED")
- Console.ResetColor()
- End If
- End Sub
- _myHubProxy = _hubConnection.CreateHubProxy("myHub")
- Await _hubConnection.Start()
- _myHubProxy.[On](Of String)("heartbeat", Sub() Console.Write("Recieved heartbeat " & vbLf))
- End Function
- Sub Main()
- Try
- InitiateConnection().Wait()
- Catch ex As Exception
- Console.WriteLine( ex.ToString())
- End Try
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement