SocketAsyncEventArgs 构造函数

定义

重载

SocketAsyncEventArgs()

创建一个空的 SocketAsyncEventArgs 实例。

SocketAsyncEventArgs(Boolean)

初始化 SocketAsyncEventArgs

SocketAsyncEventArgs()

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

创建一个空的 SocketAsyncEventArgs 实例。

public:
 SocketAsyncEventArgs();
public SocketAsyncEventArgs ();
Public Sub New ()

例外

该平台不受支持。

示例

下面的代码示例表示可重用 SocketAsyncEventArgs 对象的集合。

// 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; }
    }
}

注解

调用此构造函数后,所有属性都将具有其默认值:

调用方必须先设置适当的属性,然后才能将对象传递到相应的异步套接字 (xxxAsync) 方法。

适用于

SocketAsyncEventArgs(Boolean)

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

初始化 SocketAsyncEventArgs

public:
 SocketAsyncEventArgs(bool unsafeSuppressExecutionContextFlow);
public SocketAsyncEventArgs (bool unsafeSuppressExecutionContextFlow);
new System.Net.Sockets.SocketAsyncEventArgs : bool -> System.Net.Sockets.SocketAsyncEventArgs
Public Sub New (unsafeSuppressExecutionContextFlow As Boolean)

参数

unsafeSuppressExecutionContextFlow
Boolean

是否禁用执行上下文的捕获和流。 仅当执行上下文流由较高层处理时,才应禁用它。

适用于