This documentation is archived and is not being maintained.

LingerOption.LingerTime Property

Gets or sets the amount of time to remain connected after calling the Socket.Close method if data remains to be sent.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

public int LingerTime { get; set; }
/** @property */
public int get_LingerTime ()

/** @property */
public void set_LingerTime (int value)

public function get LingerTime () : int

public function set LingerTime (value : int)

Not applicable.

Property Value

The amount of time, in seconds, to remain connected after calling Socket.Close.

Use this value if you want to determine how long a closed Socket will attempt totransfer unsent data before timing out. You can also set this value to the desired time-out period, in seconds. If the Enabled property is true, and you set LingerTime to 0, the Socket will attempt to send data until there is no data left in the outgoing network buffer. If you change this value, you must pass the altered LingerOption to the SetSocketOption or LingerState method.

The following example displays the value of this property.

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.get_ASCII().GetString(s.
        SocketOptionName.SendTimeout, 4)));
    // blocks until send returns
    int i = s.Send(msg);
    // blocks until read returns
    ubyte bytes[] = new ubyte[1024];

    //Display to the screen
    Console.WriteLine("If data remains to be sent, this application "
        + "will stay open for " + ((LingerOption)(s.
} //SetSocketOptions

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0