HubConnection.Closed Event

Definition

Occurs when the connection is closed. The connection could be closed due to an error or due to either the server or client intentionally closing the connection without error.

public:
 event Func<Exception ^, System::Threading::Tasks::Task ^> ^ Closed;
public event Func<Exception,System.Threading.Tasks.Task> Closed;
public event Func<Exception?,System.Threading.Tasks.Task>? Closed;
member this.Closed : Func<Exception, System.Threading.Tasks.Task> 
Public Event Closed As Func(Of Exception, Task) 

Event Type

Examples

The following example attaches a handler to the Closed event, and checks the provided argument to determine if there was an error:

connection.Closed += (exception) =>
{
    if (exception == null)
    {
        Console.WriteLine("Connection closed without error.");
    }
    else
    {
        Console.WriteLine($"Connection closed due to an error: {exception}");
    }
};

Remarks

If this event was triggered from a connection error, the Exception that occurred will be passed in as the sole argument to this handler. If this event was triggered intentionally by either the client or server, then the argument will be null.

Applies to