mscorlib(4.0.0.0) API with additions
Overlapped.cs
2 using System.Security;
3 
4 namespace System.Threading
5 {
7  [ComVisible(true)]
8  public class Overlapped
9  {
10  private OverlappedData m_overlappedData;
11 
12  private static PinnableBufferCache s_overlappedDataCache = new PinnableBufferCache("System.Threading.OverlappedData", () => new OverlappedData());
13 
17  {
18  get
19  {
20  return m_overlappedData.m_asyncResult;
21  }
22  set
23  {
24  m_overlappedData.m_asyncResult = value;
25  }
26  }
27 
30  public int OffsetLow
31  {
32  get
33  {
34  return m_overlappedData.m_nativeOverlapped.OffsetLow;
35  }
36  set
37  {
38  m_overlappedData.m_nativeOverlapped.OffsetLow = value;
39  }
40  }
41 
44  public int OffsetHigh
45  {
46  get
47  {
48  return m_overlappedData.m_nativeOverlapped.OffsetHigh;
49  }
50  set
51  {
52  m_overlappedData.m_nativeOverlapped.OffsetHigh = value;
53  }
54  }
55 
58  [Obsolete("This property is not 64-bit compatible. Use EventHandleIntPtr instead. http://go.microsoft.com/fwlink/?linkid=14202")]
59  public int EventHandle
60  {
61  get
62  {
63  return m_overlappedData.UserHandle.ToInt32();
64  }
65  set
66  {
67  m_overlappedData.UserHandle = new IntPtr(value);
68  }
69  }
70 
73  [ComVisible(false)]
75  {
76  get
77  {
78  return m_overlappedData.UserHandle;
79  }
80  set
81  {
82  m_overlappedData.UserHandle = value;
83  }
84  }
85 
86  internal _IOCompletionCallback iocbHelper => m_overlappedData.m_iocbHelper;
87 
88  internal unsafe IOCompletionCallback UserCallback
89  {
90  [SecurityCritical]
91  get
92  {
93  return m_overlappedData.m_iocb;
94  }
95  }
96 
98  public Overlapped()
99  {
100  m_overlappedData = (OverlappedData)s_overlappedDataCache.Allocate();
101  m_overlappedData.m_overlapped = this;
102  }
103 
109  public Overlapped(int offsetLo, int offsetHi, IntPtr hEvent, IAsyncResult ar)
110  {
111  m_overlappedData = (OverlappedData)s_overlappedDataCache.Allocate();
112  m_overlappedData.m_overlapped = this;
113  m_overlappedData.m_nativeOverlapped.OffsetLow = offsetLo;
114  m_overlappedData.m_nativeOverlapped.OffsetHigh = offsetHi;
115  m_overlappedData.UserHandle = hEvent;
116  m_overlappedData.m_asyncResult = ar;
117  }
118 
124  [Obsolete("This constructor is not 64-bit compatible. Use the constructor that takes an IntPtr for the event handle. http://go.microsoft.com/fwlink/?linkid=14202")]
125  public Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar)
126  : this(offsetLo, offsetHi, new IntPtr(hEvent), ar)
127  {
128  }
129 
134  [SecurityCritical]
135  [Obsolete("This method is not safe. Use Pack (iocb, userData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
136  [CLSCompliant(false)]
138  {
139  return Pack(iocb, null);
140  }
141 
147  [SecurityCritical]
148  [CLSCompliant(false)]
149  [ComVisible(false)]
150  public unsafe NativeOverlapped* Pack(IOCompletionCallback iocb, object userData)
151  {
152  return m_overlappedData.Pack(iocb, userData);
153  }
154 
159  [SecurityCritical]
160  [Obsolete("This method is not safe. Use UnsafePack (iocb, userData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
161  [CLSCompliant(false)]
163  {
164  return UnsafePack(iocb, null);
165  }
166 
173  [SecurityCritical]
174  [CLSCompliant(false)]
175  [ComVisible(false)]
176  public unsafe NativeOverlapped* UnsafePack(IOCompletionCallback iocb, object userData)
177  {
178  return m_overlappedData.UnsafePack(iocb, userData);
179  }
180 
186  [SecurityCritical]
187  [CLSCompliant(false)]
188  public unsafe static Overlapped Unpack(NativeOverlapped* nativeOverlappedPtr)
189  {
190  if (nativeOverlappedPtr == null)
191  {
192  throw new ArgumentNullException("nativeOverlappedPtr");
193  }
194  return OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr).m_overlapped;
195  }
196 
201  [SecurityCritical]
202  [CLSCompliant(false)]
203  public unsafe static void Free(NativeOverlapped* nativeOverlappedPtr)
204  {
205  if (nativeOverlappedPtr == null)
206  {
207  throw new ArgumentNullException("nativeOverlappedPtr");
208  }
209  Overlapped overlapped = OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr).m_overlapped;
210  OverlappedData.FreeNativeOverlapped(nativeOverlappedPtr);
211  OverlappedData overlappedData = overlapped.m_overlappedData;
212  overlapped.m_overlappedData = null;
213  overlappedData.ReInitialize();
214  s_overlappedDataCache.Free(overlappedData);
215  }
216  }
217 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe NativeOverlapped * Pack(IOCompletionCallback iocb)
Packs the current instance into a T:System.Threading.NativeOverlapped structure, specifying the deleg...
Definition: Overlapped.cs:137
static unsafe Overlapped Unpack(NativeOverlapped *nativeOverlappedPtr)
Unpacks the specified unmanaged T:System.Threading.NativeOverlapped structure into a managed T:System...
Definition: Overlapped.cs:188
unsafe NativeOverlapped * Pack(IOCompletionCallback iocb, object userData)
Packs the current instance into a T:System.Threading.NativeOverlapped structure, specifying a delegat...
Definition: Overlapped.cs:150
Definition: __Canon.cs:3
Provides a managed representation of a Win32 OVERLAPPED structure, including methods to transfer info...
Definition: Overlapped.cs:8
static unsafe void Free(NativeOverlapped *nativeOverlappedPtr)
Frees the unmanaged memory associated with a native overlapped structure allocated by the Overload:Sy...
Definition: Overlapped.cs:203
unsafe NativeOverlapped * UnsafePack(IOCompletionCallback iocb)
Packs the current instance into a T:System.Threading.NativeOverlapped structure specifying the delega...
Definition: Overlapped.cs:162
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
Receives the error code, number of bytes, and overlapped value type when an I/O operation completes o...
int OffsetHigh
Gets or sets the high-order word of the file position at which to start the transfer....
Definition: Overlapped.cs:45
int EventHandle
Gets or sets the 32-bit integer handle to a synchronization event that is signaled when the I/O opera...
Definition: Overlapped.cs:60
IntPtr EventHandleIntPtr
Gets or sets the handle to the synchronization event that is signaled when the I/O operation is compl...
Definition: Overlapped.cs:75
Represents the status of an asynchronous operation.
Definition: IAsyncResult.cs:9
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
IAsyncResult AsyncResult
Gets or sets the object that provides status information on the I/O operation.
Definition: Overlapped.cs:17
Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar)
Initializes a new instance of the T:System.Threading.Overlapped class with the specified file positio...
Definition: Overlapped.cs:125
int OffsetLow
Gets or sets the low-order word of the file position at which to start the transfer....
Definition: Overlapped.cs:31
unsafe NativeOverlapped * UnsafePack(IOCompletionCallback iocb, object userData)
Packs the current instance into a T:System.Threading.NativeOverlapped structure, specifying the deleg...
Definition: Overlapped.cs:176
Overlapped()
Initializes a new, empty instance of the T:System.Threading.Overlapped class.
Definition: Overlapped.cs:98
Provides an explicit layout that is visible from unmanaged code and that will have the same layout as...
Overlapped(int offsetLo, int offsetHi, IntPtr hEvent, IAsyncResult ar)
Initializes a new instance of the T:System.Threading.Overlapped class with the specified file positio...
Definition: Overlapped.cs:109