本文整理匯總了C#中CloseStatusCode.CheckIfValidCloseParameters方法的典型用法代碼示例。如果您正苦於以下問題:C# CloseStatusCode.CheckIfValidCloseParameters方法的具體用法?C# CloseStatusCode.CheckIfValidCloseParameters怎麽用?C# CloseStatusCode.CheckIfValidCloseParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CloseStatusCode
的用法示例。
在下文中一共展示了CloseStatusCode.CheckIfValidCloseParameters方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CloseAsync
/// <summary>
/// Closes the WebSocket connection asynchronously with the specified
/// <see cref="CloseStatusCode"/> and <see cref="string"/>, and releases
/// all associated resources.
/// </summary>
/// <remarks>
/// <para>
/// This method doesn't wait for the close to be complete.
/// </para>
/// <para>
/// This method emits a <see cref="OnError"/> event if the size of <paramref name="reason"/>
/// is greater than 123 bytes.
/// </para>
/// </remarks>
/// <param name="code">
/// One of the <see cref="CloseStatusCode"/> enum values, represents the status code
/// indicating the reason for the close.
/// </param>
/// <param name="reason">
/// A <see cref="string"/> that represents the reason for the close.
/// </param>
public void CloseAsync (CloseStatusCode code, string reason)
{
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseParameters (reason);
if (msg != null) {
_logger.Error (msg);
error ("An error has occurred in closing the connection.", null);
return;
}
if (code.IsNoStatusCode ()) {
closeAsync (new CloseEventArgs (), true, true);
return;
}
var send = !code.IsReserved ();
closeAsync (new CloseEventArgs (code, reason), send, send);
}