SocketAsyncEventArgs Construtores

Definição

Sobrecargas

Name Description
SocketAsyncEventArgs()

Cria uma instância vazia SocketAsyncEventArgs .

SocketAsyncEventArgs(Boolean)

Inicializa o SocketAsyncEventArgs.

SocketAsyncEventArgs()

Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs

Cria uma instância vazia SocketAsyncEventArgs .

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

Exceções

A plataforma não é suportada.

Exemplos

O seguinte exemplo de código representa uma coleção de objetos reutilizáveis 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; }
    }
}

Observações

Depois de chamar este construtor, todas as propriedades terão os seus valores predefinidos:

O chamador deve definir as propriedades apropriadas antes de passar o objeto para o método apropriado do socket assíncrono (xxxAsync).

Aplica-se a

SocketAsyncEventArgs(Boolean)

Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs
Origem:
SocketAsyncEventArgs.cs

Inicializa o 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)

Parâmetros

unsafeSuppressExecutionContextFlow
Boolean

Se deve desativar o contexto de captura e fluxo de execução. O fluxo de contexto de execução só deve ser desativado se for tratado por camadas superiores.

Aplica-se a