LingerOption.LingerTime 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置在调用 Close() 方法后仍有数据要发送的情况下将保持连接的时间量。
public:
 property int LingerTime { int get(); void set(int value); };public int LingerTime { get; set; }member this.LingerTime : int with get, setPublic Property LingerTime As Integer属性值
调用 Close() 后保持连接的时间量(以秒为单位)。
示例
以下示例显示此属性的值。
Console.WriteLine("This application will timeout if Send does not return within " + Encoding.ASCII.GetString(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4)));
// blocks until send returns
int i = s.Send(msg);
// blocks until read returns
byte[] bytes = new byte[1024];
s.Receive(bytes);
// Display to the screen
Console.WriteLine(Encoding.ASCII.GetString(bytes));
s.Shutdown(SocketShutdown.Both);
Console.WriteLine("If data remains to be sent, this application will stay open for " + ((LingerOption)s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger)).LingerTime.ToString());
s.Close();
    Console.WriteLine(("This application will timeout if Send does not return within " + Encoding.ASCII.GetString(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4))))
    ' blocks until send returns
    Dim i As Integer = s.Send(msg)
    ' blocks until read returns
    Dim bytes(1024) As Byte
    s.Receive(bytes)
    'Display to the screen
    Console.WriteLine(Encoding.ASCII.GetString(bytes))
    s.Shutdown(SocketShutdown.Both)
    Console.WriteLine(("If data remains to be sent, this application will stay open for " + CType(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger), LingerOption).LingerTime.ToString()))
    s.Close()
End Sub
注解
如果要确定关闭 Socket 后在超时之前尝试传输未发送数据的时间长度,请使用此值。还可以将此值设置为所需的超时期限(以秒为单位)。
              Enabled如果 属性为 true,并且设置为 LingerTime 0,则 Socket 放弃要发送到传出网络缓冲区中的任何挂起数据。 如果更改此值,则必须将更改的 LingerOption 实例传递给 SetSocketOption 方法或设置 LingerState 或 LingerState 属性。
下表描述了 属性和 存储在 属性中的 LingerTime 属性LingerState的Enabled可能值的行为。
| enable | seconds | 行为 | 
|---|---|---|
| false(禁用) ,默认值 | 超时不适用, (默认) 。 | 尝试为面向连接的套接字发送挂起数据 (TCP,例如,) 直到默认 IP 协议超时过期。 | 
| true已启用 () | 非零超时 | 尝试发送挂起的数据,直到指定的超时过期,如果尝试失败,Winsock 将重置连接。 | 
| true已启用 () | 零超时。 | 放弃任何挂起的数据。 对于面向连接的套接字 (TCP(例如) ),Winsock 会重置连接。 | 
IP 堆栈根据连接的往返时间计算要使用的默认 IP 协议超时期限。 在大多数情况下,堆栈计算的超时比应用程序定义的超时更相关。 这是未设置 属性时 LingerState 套接字的默认行为。
LingerTime如果属性中LingerState存储的属性设置为大于默认 IP 协议超时,则默认 IP 协议超时仍将应用并替代。