SocketAsyncEventArgs Constructors

Definition

Overloads

SocketAsyncEventArgs()

Source:
SocketAsyncEventArgs.cs
Source:
SocketAsyncEventArgs.cs
Source:
SocketAsyncEventArgs.cs

Creates an empty SocketAsyncEventArgs instance.

C#
public SocketAsyncEventArgs();

Exceptions

The platform is not supported.

Examples

The following code example represents a collection of reusable SocketAsyncEventArgs objects.

C#
// Represents a collection of reusable SocketAsyncEventArgs objects.
class SocketAsyncEventArgsPool
{
    Stack<SocketAsyncEventArgs> m_pool;

    // Initializes the object pool to the specified size
    //
    // The "capacity" parameter is the maximum number of
    // SocketAsyncEventArgs objects the pool can hold
    public SocketAsyncEventArgsPool(int capacity)
    {
        m_pool = new Stack<SocketAsyncEventArgs>(capacity);
    }

    // Add a SocketAsyncEventArg instance to the pool
    //
    //The "item" parameter is the SocketAsyncEventArgs instance
    // to add to the pool
    public void Push(SocketAsyncEventArgs item)
    {
        if (item == null) { throw new ArgumentNullException("Items added to a SocketAsyncEventArgsPool cannot be null"); }
        lock (m_pool)
        {
            m_pool.Push(item);
        }
    }

    // Removes a SocketAsyncEventArgs instance from the pool
    // and returns the object removed from the pool
    public SocketAsyncEventArgs Pop()
    {
        lock (m_pool)
        {
            return m_pool.Pop();
        }
    }

    // The number of SocketAsyncEventArgs instances in the pool
    public int Count
    {
        get { return m_pool.Count; }
    }
}

Remarks

After calling this constructor all properties will have their default values:

The caller must set the appropriate properties prior to passing the object to the appropriate asynchronous socket (xxxAsync) method.

Applies to

.NET 10 and other versions
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, 10
.NET Framework 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
UWP 10.0

SocketAsyncEventArgs(Boolean)

Source:
SocketAsyncEventArgs.cs
Source:
SocketAsyncEventArgs.cs
Source:
SocketAsyncEventArgs.cs

Initializes the SocketAsyncEventArgs.

C#
public SocketAsyncEventArgs(bool unsafeSuppressExecutionContextFlow);

Parameters

unsafeSuppressExecutionContextFlow
Boolean

Whether to disable the capturing and flow of execution context. Execution context flow should only be disabled if it's handled by higher layers.

Applies to

.NET 10 and other versions
Product Versions
.NET 5, 6, 7, 8, 9, 10