Socket.Blocking Socket.Blocking Socket.Blocking Socket.Blocking Property


获取或设置一个值,该值指示 Socket 是否处于阻止模式。Gets or sets a value that indicates whether the Socket is in blocking mode.

 property bool Blocking { bool get(); void set(bool value); };
public bool Blocking { get; set; }
member this.Blocking : bool with get, set
Public Property Blocking As Boolean


如果 Socket 将阻止,则为 true;否则为 falsetrue if the Socket will block; otherwise, false. 默认值为 trueThe default is true.


尝试访问套接字时出错。An error occurred when attempting to access the socket.


Blocking属性指示是否Socket处于阻止模式。The Blocking property indicates whether a Socket is in blocking mode.

如果您是在阻止模式下,并且进行方法调用这不会立即完成,你的应用程序将请求的操作完成之前阻止执行。If you are in blocking mode, and you make a method call which does not complete immediately, your application will block execution until the requested operation completes. 如果要继续执行,即使请求的操作未完成,更改执行Blocking属性设置为falseIf you want execution to continue even though the requested operation is not complete, change the Blocking property to false. Blocking属性不起对异步方法。The Blocking property has no effect on asynchronous methods. 如果是发送和接收数据以异步方式并且想要阻止执行,使用ManualResetEvent类。If you are sending and receiving data asynchronously and want to block execution, use the ManualResetEvent class.


如果你收到SocketException,使用SocketException.ErrorCode属性来获取特定错误代码。If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. 获取此代码后,请参阅Windows 套接字版本 2 API 错误代码有关错误的详细说明的文档。After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.


当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅在.NET Framework 中进行网络跟踪For more information, see Network Tracing in the .NET Framework.