LingerOption.Enabled Property

Definition

Gets or sets a value that indicates whether to linger after the Socket is closed.

public bool Enabled { get; set; }

Property Value

true if the Socket should linger after Close() is called; otherwise, false.

Remarks

You can use the Enabled property to determine whether the Socket will linger after closing. Change this value to true or false and pass the altered LingerOption to the SetSocketOption method or set the LingerState or LingerState property.to disable or enable lingering.

The following table describes the behavior for the possible values of the Enabled property and the LingerTime property stored in the LingerState property.

enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.

The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the LingerState property is not set.

When the LingerTime property stored in the LingerState property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and override.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1