本文整理汇总了C#中System.Threading.Overlapped类的典型用法代码示例。如果您正苦于以下问题:C# Overlapped类的具体用法?C# Overlapped怎么用?C# Overlapped使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Overlapped类属于System.Threading命名空间,在下文中一共展示了Overlapped类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateToken
/// <summary>
/// Creates a <see cref="CancellationTokenSource"/> for the given <paramref name="connectionId"/> and registers it for disconnect.
/// </summary>
/// <param name="connectionId">The connection id.</param>
/// <returns>A <see cref="CancellationTokenSource"/> that is registered for disconnect for the connection associated with the <paramref name="connectionId"/>.</returns>
public CancellationToken CreateToken(ulong connectionId)
{
Debug.WriteLine("Server: Registering connection for disconnect for connection ID: " + connectionId);
// Create a nativeOverlapped callback so we can register for disconnect callback
var overlapped = new Overlapped();
var cts = new CancellationTokenSource();
var nativeOverlapped = overlapped.UnsafePack((errorCode, numBytes, pOVERLAP) =>
{
Debug.WriteLine("Server: http.sys disconnect callback fired for connection ID: " + connectionId);
// Free the overlapped
Overlapped.Free(pOVERLAP);
// Pull the token out of the list and Cancel it.
Lazy<CancellationToken> token;
_connectionCancellationTokens.TryRemove(connectionId, out token);
cts.Cancel();
},
null);
uint hr = NativeMethods.HttpWaitForDisconnect(_requestQueueHandle, connectionId, nativeOverlapped);
if (hr != NativeMethods.HttpErrors.ERROR_IO_PENDING &&
hr != NativeMethods.HttpErrors.NO_ERROR)
{
// We got an unknown result so throw
Debug.WriteLine("Unable to register disconnect callback");
return CancellationToken.None;
}
return cts.Token;
}
开发者ID:Kazzje,项目名称:SignalR,代码行数:37,代码来源:DisconnectHandler.cs
示例2: BeginRead
internal unsafe IAsyncResult BeginRead(byte[] data, int offset, int size, AsyncCallback callback, object state)
{
bool flag;
PipeAsyncResult ar = new PipeAsyncResult(callback);
NativeOverlapped* lpOverlapped = new Overlapped(0, 0, IntPtr.Zero, ar).UnsafePack(IOCallback, data);
ar._overlapped = lpOverlapped;
fixed (byte* numRef = data)
{
flag = NativePipe.ReadFile(this._handle, numRef + offset, size, IntPtr.Zero, lpOverlapped);
}
if (!flag)
{
int errorCode = Marshal.GetLastWin32Error();
if (errorCode == 0x6dL)
{
ar.CallUserCallback();
return ar;
}
if (errorCode != 0x3e5L)
{
throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ReadFailure"), new object[] { GetMessage(errorCode) }));
}
}
return ar;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:IpcPort.cs
示例3: OverlappedContext
public OverlappedContext()
{
if (OverlappedContext.completeCallback == null)
{
OverlappedContext.completeCallback = Fx.ThunkCallback(new IOCompletionCallback(CompleteCallback));
}
if (OverlappedContext.eventCallback == null)
{
OverlappedContext.eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(EventCallback));
}
if (OverlappedContext.cleanupCallback == null)
{
OverlappedContext.cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(CleanupCallback));
}
this.bufferHolder = new object[] { OverlappedContext.dummyBuffer };
this.overlapped = new Overlapped();
this.nativeOverlapped = this.overlapped.UnsafePack(OverlappedContext.completeCallback, this.bufferHolder);
// When replacing the buffer, we need to provoke the CLR to fix up the handle of the pin.
this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*)nativeOverlapped +
(IntPtr.Size == 4 ? HandleOffsetFromOverlapped32 : HandleOffsetFromOverlapped64)));
this.pinnedTarget = this.pinnedHandle.Target;
// Create the permanently rooted holder and put it in the Overlapped.
this.rootedHolder = new RootedHolder();
this.overlapped.AsyncResult = rootedHolder;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:28,代码来源:OverlappedContext.cs
示例4: OverlappedCache
internal unsafe OverlappedCache(Overlapped overlapped, object[] pinnedObjectsArray, IOCompletionCallback callback)
{
this.m_Overlapped = overlapped;
this.m_PinnedObjects = pinnedObjectsArray;
this.m_PinnedObjectsArray = pinnedObjectsArray;
this.m_NativeOverlapped = new SafeNativeOverlapped((IntPtr)((void*)overlapped.UnsafePack(callback, pinnedObjectsArray)));
}
开发者ID:BjkGkh,项目名称:R106,代码行数:7,代码来源:OverlappedCache.cs
示例5: OverlappedCache
internal OverlappedCache(System.Threading.Overlapped overlapped, object[] pinnedObjectsArray, IOCompletionCallback callback)
{
this.m_Overlapped = overlapped;
this.m_PinnedObjects = pinnedObjectsArray;
this.m_PinnedObjectsArray = pinnedObjectsArray;
this.m_NativeOverlapped = new SafeNativeOverlapped(overlapped.UnsafePack(callback, pinnedObjectsArray));
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:OverlappedCache.cs
示例6: Unpack
unsafe public static Overlapped Unpack (NativeOverlapped *nativeOverlappedPtr)
{
if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
throw new ArgumentNullException ("nativeOverlappedPtr");
Overlapped result = new Overlapped ();
result.offsetL = nativeOverlappedPtr->OffsetLow;
result.offsetH = nativeOverlappedPtr->OffsetHigh;
result.evt = (int)nativeOverlappedPtr->EventHandle;
return result;
}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:Overlapped.cs
示例7: HttpResponseStreamAsyncResult
internal unsafe HttpResponseStreamAsyncResult(object asyncObject, object userState, AsyncCallback callback, byte[] buffer, int offset, int size, bool chunked, bool sentHeaders) : base(asyncObject, userState, callback)
{
this.m_SentHeaders = sentHeaders;
Overlapped overlapped = new Overlapped {
AsyncResult = this
};
if (size == 0)
{
this.m_DataChunks = null;
this.m_pOverlapped = overlapped.Pack(s_IOCallback, null);
}
else
{
this.m_DataChunks = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK[chunked ? 3 : 1];
object[] userData = new object[1 + this.m_DataChunks.Length];
userData[this.m_DataChunks.Length] = this.m_DataChunks;
int num = 0;
byte[] arr = null;
if (chunked)
{
arr = ConnectStream.GetChunkHeader(size, out num);
this.m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
this.m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
this.m_DataChunks[0].BufferLength = (uint) (arr.Length - num);
userData[0] = arr;
this.m_DataChunks[1] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
this.m_DataChunks[1].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
this.m_DataChunks[1].BufferLength = (uint) size;
userData[1] = buffer;
this.m_DataChunks[2] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
this.m_DataChunks[2].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
this.m_DataChunks[2].BufferLength = (uint) NclConstants.CRLF.Length;
userData[2] = NclConstants.CRLF;
}
else
{
this.m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
this.m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
this.m_DataChunks[0].BufferLength = (uint) size;
userData[0] = buffer;
}
this.m_pOverlapped = overlapped.Pack(s_IOCallback, userData);
if (chunked)
{
this.m_DataChunks[0].pBuffer = (byte*) Marshal.UnsafeAddrOfPinnedArrayElement(arr, num);
this.m_DataChunks[1].pBuffer = (byte*) Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
this.m_DataChunks[2].pBuffer = (byte*) Marshal.UnsafeAddrOfPinnedArrayElement(NclConstants.CRLF, 0);
}
else
{
this.m_DataChunks[0].pBuffer = (byte*) Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:54,代码来源:HttpResponseStreamAsyncResult.cs
示例8: AsyncFileStream_AsyncResult
internal AsyncFileStream_AsyncResult( AsyncCallback userCallback, Object stateObject, bool isWrite )
{
m_userCallback = userCallback;
m_userStateObject = stateObject;
m_waitHandle = new ManualResetEvent( false );
m_isWrite = isWrite;
Overlapped overlapped = new Overlapped( 0, 0, IntPtr.Zero, this );
m_overlapped = overlapped.Pack( s_callback, null );
}
开发者ID:prabby,项目名称:miniclr,代码行数:12,代码来源:Streams.cs
示例9: InternalFree
private void InternalFree()
{
this.m_Overlapped = null;
this.m_PinnedObjects = null;
if (this.m_NativeOverlapped != null)
{
if (!this.m_NativeOverlapped.IsInvalid)
{
this.m_NativeOverlapped.Dispose();
}
this.m_NativeOverlapped = null;
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:OverlappedCache.cs
示例10: ReInitialize
internal void ReInitialize()
{
this.m_asyncResult = null;
this.m_iocb = null;
this.m_iocbHelper = null;
this.m_overlapped = null;
this.m_userObject = null;
this.m_pinSelf = IntPtr.Zero;
this.m_userObjectInternal = IntPtr.Zero;
this.m_AppDomainId = 0;
this.m_nativeOverlapped.EventHandle = IntPtr.Zero;
this.m_isArray = 0;
this.m_nativeOverlapped.InternalHigh = IntPtr.Zero;
}
开发者ID:randomize,项目名称:VimConfig,代码行数:14,代码来源:OverlappedData.cs
示例11: CreateToken
private unsafe CancellationToken CreateToken(ulong connectionId)
{
// Create a nativeOverlapped callback so we can register for disconnect callback
var overlapped = new Overlapped();
var cts = new CancellationTokenSource();
CancellationToken returnToken = cts.Token;
NativeOverlapped* nativeOverlapped = overlapped.UnsafePack(
(errorCode, numBytes, overlappedPtr) =>
{
// Free the overlapped
Overlapped.Free(overlappedPtr);
if (errorCode != NativeMethods.HttpErrors.NO_ERROR)
{
LogHelper.LogException(_logger, "IOCompletionCallback", new Win32Exception((int)errorCode));
}
// Pull the token out of the list and Cancel it.
ConnectionCancellation cancellation;
_connectionCancellationTokens.TryRemove(connectionId, out cancellation);
bool success = ThreadPool.UnsafeQueueUserWorkItem(CancelToken, cts);
Debug.Assert(success, "Unable to queue disconnect notification.");
},
null);
uint hr = NativeMethods.HttpWaitForDisconnect(_requestQueueHandle, connectionId, nativeOverlapped);
if (hr != NativeMethods.HttpErrors.ERROR_IO_PENDING &&
hr != NativeMethods.HttpErrors.NO_ERROR)
{
// We got an unknown result, assume the connection has been closed.
Overlapped.Free(nativeOverlapped);
ConnectionCancellation cancellation;
_connectionCancellationTokens.TryRemove(connectionId, out cancellation);
LogHelper.LogException(_logger, "HttpWaitForDisconnect", new Win32Exception((int)hr));
cts.Cancel();
cts.Dispose();
}
return returnToken;
}
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:43,代码来源:DisconnectHandler.cs
示例12: OverlappedContext
public unsafe OverlappedContext()
{
if (completeCallback == null)
{
completeCallback = Fx.ThunkCallback(new IOCompletionCallback(OverlappedContext.CompleteCallback));
}
if (eventCallback == null)
{
eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.EventCallback));
}
if (cleanupCallback == null)
{
cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.CleanupCallback));
}
this.bufferHolder = new object[] { dummyBuffer };
this.overlapped = new Overlapped();
this.nativeOverlapped = this.overlapped.UnsafePack(completeCallback, this.bufferHolder);
this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*) (this.nativeOverlapped + (((IntPtr.Size == 4) ? -4 : -3) * sizeof(IntPtr)))));
this.pinnedTarget = this.pinnedHandle.Target;
this.rootedHolder = new RootedHolder();
this.overlapped.AsyncResult = this.rootedHolder;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:OverlappedContext.cs
示例13: Reset
internal void Reset(uint size) {
if (size == m_Size)
{
return;
}
if (m_Size != 0)
{
Overlapped.Free(m_pOverlapped);
}
m_Size = size;
if (size == 0)
{
m_pOverlapped = null;
m_MemoryBlob = null;
m_BackingBuffer = null;
return;
}
m_BackingBuffer = new byte[checked((int) size)];
Overlapped overlapped = new Overlapped();
overlapped.AsyncResult = this;
m_pOverlapped = overlapped.Pack(s_IOCallback, m_BackingBuffer);
m_MemoryBlob = (UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO*) Marshal.UnsafeAddrOfPinnedArrayElement(m_BackingBuffer, 0);
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:23,代码来源:HttpListenerRequest.cs
示例14: SetupOverlappedMultiple
// Method to setup an Overlapped object with with multiple buffers pinned.
unsafe private void SetupOverlappedMultiple() {
ArraySegment<byte>[] tempList = new ArraySegment<byte>[m_BufferList.Count];
m_BufferList.CopyTo(tempList, 0);
// Alloc new Overlapped.
m_Overlapped = new Overlapped();
// Number of things to pin is number of buffers.
// Ensure we have properly sized object array.
if(m_ObjectsToPin == null || (m_ObjectsToPin.Length != tempList.Length)) {
m_ObjectsToPin = new object[tempList.Length];
}
// Fill in object array.
for(int i = 0; i < (tempList.Length); i++) {
m_ObjectsToPin[i] = tempList[i].Array;
}
if(m_WSABufferArray == null || m_WSABufferArray.Length != tempList.Length) {
m_WSABufferArray = new WSABuffer[tempList.Length];
}
// Pin buffers and fill in WSABuffer descriptor pointers and lengths
#if SOCKETTHREADPOOL
m_Overlapped.AsyncResult = new DummyAsyncResult(CompletionPortCallback);
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(null, m_ObjectsToPin));
#else
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(CompletionPortCallback, m_ObjectsToPin));
#endif
for(int i = 0; i < tempList.Length; i++) {
ArraySegment<byte> localCopy = tempList[i];
ValidationHelper.ValidateSegment(localCopy);
m_WSABufferArray[i].Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(localCopy.Array, localCopy.Offset);
m_WSABufferArray[i].Length = localCopy.Count;
}
m_PinState = PinState.MultipleBuffer;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:39,代码来源:Socket.cs
示例15: SetupOverlappedSingle
// Method to setup an Overlapped object with either m_Buffer or m_AcceptBuffer pinned.
unsafe private void SetupOverlappedSingle(bool pinSingleBuffer) {
// Alloc new Overlapped.
m_Overlapped = new Overlapped();
// Pin buffer, get native pointers, and fill in WSABuffer descriptor.
if(pinSingleBuffer) {
if(m_Buffer != null) {
#if SOCKETTHREADPOOL
m_Overlapped.AsyncResult = new DummyAsyncResult(CompletionPortCallback);
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(null, m_Buffer));
#else
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(CompletionPortCallback, m_Buffer));
#endif
m_PinnedSingleBuffer = m_Buffer;
m_PinnedSingleBufferOffset = m_Offset;
m_PinnedSingleBufferCount = m_Count;
m_PtrSingleBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(m_Buffer, m_Offset);
m_PtrAcceptBuffer = IntPtr.Zero;
m_WSABuffer.Pointer = m_PtrSingleBuffer;
m_WSABuffer.Length = m_Count;
m_PinState = PinState.SingleBuffer;
} else {
#if SOCKETTHREADPOOL
m_Overlapped.AsyncResult = new DummyAsyncResult(CompletionPortCallback);
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(null, null));
#else
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(CompletionPortCallback, null));
#endif
m_PinnedSingleBuffer = null;
m_PinnedSingleBufferOffset = 0;
m_PinnedSingleBufferCount = 0;
m_PtrSingleBuffer = IntPtr.Zero;
m_PtrAcceptBuffer = IntPtr.Zero;
m_WSABuffer.Pointer = m_PtrSingleBuffer;
m_WSABuffer.Length = m_Count;
m_PinState = PinState.NoBuffer;
}
} else {
#if SOCKETTHREADPOOL
m_Overlapped.AsyncResult = new DummyAsyncResult(CompletionPortCallback);
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(null, m_AcceptBuffer));
#else
m_PtrNativeOverlapped = new SafeNativeOverlapped(m_Overlapped.UnsafePack(CompletionPortCallback, m_AcceptBuffer));
#endif
m_PinnedAcceptBuffer = m_AcceptBuffer;
m_PtrAcceptBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(m_AcceptBuffer, 0);
m_PtrSingleBuffer = IntPtr.Zero;
m_PinState = PinState.SingleAcceptBuffer;
}
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:52,代码来源:Socket.cs
示例16: FreeOverlapped
// Method to clean up any existing Overlapped object and related state variables.
private void FreeOverlapped(bool checkForShutdown) {
if (!checkForShutdown || !NclUtilities.HasShutdownStarted) {
// Free the overlapped object
if(m_PtrNativeOverlapped != null && !m_PtrNativeOverlapped.IsInvalid) {
m_PtrNativeOverlapped.Dispose();
m_PtrNativeOverlapped = null;
m_Overlapped = null;
m_PinState = PinState.None;
m_PinnedAcceptBuffer = null;
m_PinnedSingleBuffer = null;
m_PinnedSingleBufferOffset = 0;
m_PinnedSingleBufferCount = 0;
}
// Free any alloc'd GCHandles
if(m_SocketAddressGCHandle.IsAllocated) {
m_SocketAddressGCHandle.Free();
}
if(m_WSAMessageBufferGCHandle.IsAllocated) {
m_WSAMessageBufferGCHandle.Free();
}
if(m_WSARecvMsgWSABufferArrayGCHandle.IsAllocated) {
m_WSARecvMsgWSABufferArrayGCHandle.Free();
}
if(m_ControlBufferGCHandle.IsAllocated) {
m_ControlBufferGCHandle.Free();
}
}
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:33,代码来源:Socket.cs
示例17: GetOverlappedData
internal static OverlappedData GetOverlappedData(Overlapped overlapped)
{
OverlappedData data = null;
Interlocked.Exchange(ref m_overlappedDataCacheAccessed, 1);
while (true)
{
OverlappedDataCacheLine overlappedDataCache = s_firstFreeCacheLine;
if (overlappedDataCache == null)
{
overlappedDataCache = m_overlappedDataCache;
}
while (overlappedDataCache != null)
{
for (short i = 0; i < 0x10; i = (short) (i + 1))
{
if (overlappedDataCache.m_items[i] != null)
{
data = Interlocked.Exchange<OverlappedData>(ref overlappedDataCache.m_items[i], null);
if (data != null)
{
s_firstFreeCacheLine = overlappedDataCache;
data.m_overlapped = overlapped;
return data;
}
}
}
overlappedDataCache = overlappedDataCache.m_next;
}
GrowOverlappedDataCache();
}
}
开发者ID:randomize,项目名称:VimConfig,代码行数:31,代码来源:OverlappedDataCache.cs
示例18: ReadThread
//--------------------------------------------------------------------------
// Data reception
//--------------------------------------------------------------------------
unsafe void ReadThread(ThreadContext ctx)
{
System.Threading.Thread.CurrentThread.Name = "BluetoothConnection.ReadThread";
EventWaitHandle asyncReadCompleteEvent = new EventWaitHandle(false, System.Threading.EventResetMode.ManualReset);
NativeOverlapped* pNativeOverlapped = null;
byte[] rgbBuffer = new byte[64];
try {
WaitHandle[] waitHandles = new WaitHandle[2];
waitHandles[0] = asyncReadCompleteEvent;
waitHandles[1] = ctx.StopEvent;
//
while (!ctx.StopRequest)
{
// Issue an async read
//
asyncReadCompleteEvent.Reset();
Overlapped overlapped = new Overlapped(0, 0, asyncReadCompleteEvent.SafeWaitHandle.DangerousGetHandle(), null);
pNativeOverlapped = overlapped.Pack(null, rgbBuffer);
int cbRead = 0;
bool fSuccess = ReadFile(this.hSerialPort, rgbBuffer, rgbBuffer.Length, out cbRead, new IntPtr(pNativeOverlapped));
readThreadRunning.Set();
if (!fSuccess)
{
int err = Marshal.GetLastWin32Error();
if (err != ERROR_IO_PENDING)
ThrowWin32Error(err);
}
// Wait until either the async read completes or we're asked to stop
int iWait = WaitHandle.WaitAny(waitHandles);
// Process according to which event fired
switch (iWait)
{
case 0: // Async read completed
{
ThrowIfFail(GetOverlappedResult(this.hSerialPort, new IntPtr(pNativeOverlapped), ref cbRead, System.Convert.ToByte(true)));
// Program.Trace("async read complete: 0x{0:08X} 0x{1:08X} cb={2}", new IntPtr(pNativeOverlapped), this.hSerialPort, cbRead);
// Record the new data and process any packets that are now complete
this.RecordIncomingData(rgbBuffer, cbRead);
ProcessPacketIfPossible();
System.Threading.Overlapped.Free(pNativeOverlapped);
pNativeOverlapped = null;
}
break;
case 1: // StopEvent
break;
// end switch
}
}
}
finally
{
CancelIo(this.hSerialPort);
asyncReadCompleteEvent.Close();
if (pNativeOverlapped != null)
{
System.Threading.Overlapped.Free(pNativeOverlapped);
pNativeOverlapped = null;
}
}
}
开发者ID:redshiftrobotics,项目名称:telemetry_Archive,代码行数:73,代码来源:Connection.cs
示例19: Send
//--------------------------------------------------------------------------
// Data transmission
//--------------------------------------------------------------------------
public override bool Send(NxtMessage msg)
{
bool fResult = false;
if (this.IsOpen)
{
try {
lock (this.msgReplyTargets)
{
this.msgReplyTargets.Add(msg);
}
byte[] rgbToSend = msg.DataForBluetoothTransmission;
int cbSent = 0;
unsafe
{
EventWaitHandle asyncWriteCompleteEvent = new EventWaitHandle(false, System.Threading.EventResetMode.ManualReset);
Overlapped overlappedWrite = new Overlapped(-1, -1, asyncWriteCompleteEvent.SafeWaitHandle.DangerousGetHandle(), null);
NativeOverlapped* pNativeOverlappedWrite = overlappedWrite.Pack(null, rgbToSend);
try
{
bool fSuccess = WriteFile(this.hSerialPort, rgbToSend, rgbToSend.Length, out cbSent, new IntPtr(pNativeOverlappedWrite));
if (!fSuccess)
{
int err = Marshal.GetLastWin32Error();
if (ERROR_IO_PENDING == err)
{
asyncWriteCompleteEvent.WaitOne();
}
else
ThrowWin32Error(err);
}
}
finally
{
System.Threading.Overlapped.Free(pNativeOverlappedWrite);
}
}
msg.NoteSent();
fResult = true;
}
catch (Exception)
{
}
}
return fResult;
}
开发者ID:redshiftrobotics,项目名称:telemetry_Archive,代码行数:52,代码来源:Connection.cs
示例20: ConnectNamedPipe
public static extern bool ConnectNamedPipe(PipeHandle hNamedPipe, // handle to named pipe
Overlapped lpOverlapped // overlapped structure
);
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:3,代码来源:Win32NamedPipes.cs
注:本文中的System.Threading.Overlapped类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论