SocketAsyncEventArgs Constructor ()
.NET Framework (current version)
Creates an empty SocketAsyncEventArgs instance.
Assembly: System (in System.dll)
| Exception | Condition |
|---|---|
| NotSupportedException | The platform is not supported. |
After calling this constructor all properties will have their default values:
Object references will be null
Properties that return an integer will return zero.
The LastOperation property will be equal to None.
The SendPacketsFlags property will be equal to TransmitFileOptions::UseDefaultWorkerThread, which specifies no flags will be used.
The SocketFlags property will be equal to None.
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.
// 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; } } }
Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Available since 10
.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Show: