JimmyJimm JimmyJimm - 1 month ago 5
Vb.net Question

Convert C# lambda expression to vb.net

I have three statments in C# and have problems to convert them to vb.net, can anyone show howw this has to be done in vb.net?:

_hubConnection.Reconnecting += () =>
{
if (_hubConnection.State == ConnectionState.Reconnecting)
{
CanSend = false;
Status = "Connection reconnecting...";
}
};

_hubConnection.Closed += async () =>
{
if (_hubConnection.State == ConnectionState.Disconnected)
{
CanSend = false;
Status = "Connection lost, reconnecting in a bit...";
await Task.Delay(_reconnectDelay);
await Connect();
}
};

_hubConnection.Error += ex =>
{
LogMessages.Add(ex.ToString());
};


What i did so far (please confirm whether its ok, and last one i have no idea:

AddHandler _hubConnection.Reconnecting, Sub()
If _hubConnection.State = ConnectionState.Connected Then
CanSend = false;
Status = "Connection reconnecting..." End Sub)
End If
End Sub


The second one:

AddHandler _hubConnection.Closed, Async Sub()
If _hubConnection.State = ConnectionState.Disconnected Then
CanSend = false;
Status = "Connection lost, reconnecting in a bit...";
await Task.Delay(_reconnectDelay);
await Connect();
End If
End Sub

Answer

EDITED:

    AddHandler _hubConnection.Reconnecting, Sub()
        If _hubConnection.State = ConnectionState.Reconnecting Then
            CanSend = False
            Status = "Connection reconnecting..."
        End If
    End Sub

    AddHandler _hubConnection.Reconnected, Sub()
        If _hubConnection.State = ConnectionState.Connected Then
            Status = String.Format("Connected to {0} via {1}", _hubUrl, _hubConnection.Transport.Name)
            CanSend = True
        End If
    End Sub

    AddHandler _hubConnection.Closed, Async Sub()
        If _hubConnection.State = ConnectionState.Disconnected Then
            CanSend = False
            Status = "Connection lost, reconnecting in a bit..."
            Await Task.Delay(_reconnectDelay)
            Await Connect()
        End If
    End Sub

    AddHandler _hubConnection.Error, Sub(ex)
        LogMessages.Add(ex.ToString())
    End Sub
Comments