Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 SocketAsyncEventArgs Constructor

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
SocketAsyncEventArgs Constructor

Creates an empty SocketAsyncEventArgs instance.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Sub New
Visual Basic (Usage)
Dim instance As New SocketAsyncEventArgs()
C#
public SocketAsyncEventArgs()
Visual C++
public:
SocketAsyncEventArgs()
JScript
public function SocketAsyncEventArgs()
ExceptionCondition
NotSupportedException

The platform is not supported.

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.

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

}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker