@@ -63,13 +63,40 @@ public partial class HubConnection
63
63
private ConnectionState _connectionState ;
64
64
private int _serverProtocolMinorVersion ;
65
65
66
+ /// <summary>
67
+ /// Occurs when the connection is closed. The connection could be closed due to an error or due to either the server or client intentionally
68
+ /// closing the connection without error.
69
+ /// </summary>
70
+ /// <remarks>
71
+ /// If this event was triggered from a connection error, the <see cref="Exception"/> that occurred will be passed in as the
72
+ /// sole argument to this handler. If this event was triggered intentionally by either the client or server, then
73
+ /// the argument will be <see langword="null"/>.
74
+ /// </remarks>
75
+ /// <example>
76
+ /// The following example attaches a handler to the <see cref="Closed"/> event, and checks the provided argument to determine
77
+ /// if there was an error:
78
+ ///
79
+ /// <code>
80
+ /// connection.Closed += (exception) =>
81
+ /// {
82
+ /// if (exception == null)
83
+ /// {
84
+ /// Console.WriteLine("Connection closed without error.");
85
+ /// }
86
+ /// else
87
+ /// {
88
+ /// Console.WriteLine($"Connection closed due to an error: {exception.Message}");
89
+ /// }
90
+ /// };
91
+ /// </code>
92
+ /// </example>
66
93
public event Func < Exception , Task > Closed ;
67
94
68
95
// internal for testing purposes
69
96
internal TimeSpan TickRate { get ; set ; } = TimeSpan . FromSeconds ( 1 ) ;
70
97
71
98
/// <summary>
72
- /// Gets or sets the server timeout interval for the connection.
99
+ /// Gets or sets the server timeout interval for the connection.
73
100
/// </summary>
74
101
/// <remarks>
75
102
/// The client times out if it hasn't heard from the server for `this` long.
@@ -510,7 +537,7 @@ private void LaunchStreams(Dictionary<string, object> readers, CancellationToken
510
537
}
511
538
}
512
539
513
- // this is called via reflection using the `_sendStreamItems` field
540
+ // this is called via reflection using the `_sendStreamItems` field
514
541
private async Task SendStreamItems < T > ( string streamId , ChannelReader < T > reader , CancellationToken token )
515
542
{
516
543
Log . StartingStream ( _logger , streamId ) ;
@@ -849,7 +876,7 @@ private async Task HandshakeAsync(ConnectionState startingConnectionState, Cance
849
876
}
850
877
}
851
878
}
852
-
879
+
853
880
// shutdown if we're unable to read handshake
854
881
// Ignore HubException because we throw it when we receive a handshake response with an error
855
882
// And because we already have the error, we don't need to log that the handshake failed
@@ -1139,7 +1166,7 @@ public void Dispose()
1139
1166
private class InvocationHandlerList
1140
1167
{
1141
1168
private readonly List < InvocationHandler > _invocationHandlers ;
1142
- // A lazy cached copy of the handlers that doesn't change for thread safety.
1169
+ // A lazy cached copy of the handlers that doesn't change for thread safety.
1143
1170
// Adding or removing a handler sets this to null.
1144
1171
private InvocationHandler [ ] _copiedHandlers ;
1145
1172
0 commit comments