共用方式為


SocketAsyncEventArgs 建構函式

定義

多載

SocketAsyncEventArgs()

建立空的 SocketAsyncEventArgs 執行個體。

SocketAsyncEventArgs(Boolean)

初始化 SocketAsyncEventArgs

SocketAsyncEventArgs()

來源:
SocketAsyncEventArgs.cs
來源:
SocketAsyncEventArgs.cs
來源:
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)

來源:
SocketAsyncEventArgs.cs
來源:
SocketAsyncEventArgs.cs
來源:
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

是否要停用執行內容的擷取和流程。 只有當執行內容流程是由較高層處理時,才應停用。

適用於