HubConnection.Closed 事件

定义

关闭连接时发生。 连接可能由于错误或服务器或客户端有意关闭连接而未出错而关闭。

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) 

事件类型

示例

以下示例将处理程序附加到 Closed 事件,并检查提供的参数以确定是否存在错误:

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

注解

如果此事件是由连接错误触发的, Exception 则发生的 将作为唯一参数传入此处理程序。 如果此事件是由客户端或服务器有意触发的,则 参数将为 null

适用于