本文整理汇总了C#中System.Threading.NativeOverlapped类的典型用法代码示例。如果您正苦于以下问题:C# NativeOverlapped类的具体用法?C# NativeOverlapped怎么用?C# NativeOverlapped使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeOverlapped类属于System.Threading命名空间,在下文中一共展示了NativeOverlapped类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eject
public static bool Eject(string driveLetter)
{
bool result = false;
string fileName = string.Format(@"\\.\{0}:", driveLetter);
IntPtr deviceHandle = _CreateFile(fileName);
if (deviceHandle != INVALID_HANDLE_VALUE)
{
IntPtr null_ptr = IntPtr.Zero;
int bytesReturned;
NativeOverlapped overlapped = new NativeOverlapped();
result = DeviceIoControl(
deviceHandle,
IOCTL_STORAGE_EJECT_MEDIA,
ref null_ptr,
0,
out null_ptr,
0,
out bytesReturned,
ref overlapped);
CloseHandle(deviceHandle);
}
return result;
}
示例2: HasOverlappedIoCompleted
internal static bool HasOverlappedIoCompleted(NativeOverlapped lpOverlapped)
{
// this method is defined as a MACRO in winbase.h:
// #define HasOverlappedIoCompleted(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) != STATUS_PENDING)
// OVERLAPPED::Internal === NativeOverlapped.InternalLow
return lpOverlapped.InternalLow.ToInt32() != STATUS_PENDING;
}
示例3: ReadFile
public static extern bool ReadFile(
SafeFileHandle hFile,
byte* pBuffer,
int numBytesToRead,
out int pNumberOfBytesRead,
NativeOverlapped* lpOverlapped
);
示例4: ReadFile
public static extern bool ReadFile(
SafeFileHandle hFile,
IntPtr pBuffer,
int numberOfBytesToRead,
int[] pNumberOfBytesRead,
NativeOverlapped[] lpOverlapped // should be fixed, if not null
);
示例5: IOCallback
public unsafe static void IOCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
{
var state = ThreadPoolBoundHandle.GetNativeOverlappedState(pOverlapped);
var operation = (ReadOperation)state;
operation.ThreadPoolBoundHandle.FreeNativeOverlapped(operation.Overlapped);
operation.Offset += (int)numBytes;
var buffer = operation.BoxedBuffer.Value;
buffer.Advance((int)numBytes);
var task = buffer.FlushAsync();
if (numBytes == 0 || operation.Writer.Writing.IsCompleted)
{
operation.Writer.Complete();
// The operation can be disposed when there's nothing more to produce
operation.Dispose();
}
else if (task.IsCompleted)
{
operation.Read();
}
else
{
// Keep reading once we get the completion
task.ContinueWith((t, s) => ((ReadOperation)s).Read(), operation);
}
}
示例6: Update
public static unsafe void Update(int index, int[] analogData, byte[] digitalData)
{
//Create the structure
var state = new JoystickState();
state.Signature = (uint)0x53544143;
state.NumAnalog = (char)63;
state.NumDigital = (char)128;
state.Analog = new int[state.NumAnalog];
state.Digital = new char[state.NumDigital];
//Fill it with our data
if (analogData != null)
Array.Copy(analogData, 0, state.Analog, 0, Math.Min(analogData.Length, state.Analog.Length));
if (digitalData != null)
Array.Copy(digitalData, 0, state.Digital, 0, Math.Min(digitalData.Length, state.Digital.Length));
//Send the data
uint bytesReturned = 0;
NativeOverlapped overlapped = new NativeOverlapped();
var h = _GetHandle(index);
bool ret = DeviceIoControl(h, 0x00220000,
state, (uint)Marshal.SizeOf(state),
IntPtr.Zero, 0, ref bytesReturned, ref overlapped);
if (!ret)
{
//TODO: Do something with this?
int lastError = Marshal.GetLastWin32Error();
//Invalidate the handle
_CloseHandle(h);
_handles[index] = null;
}
}
示例7: AsyncPSCallback
private static unsafe void AsyncPSCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
{
PipeStreamAsyncResult asyncResult = (PipeStreamAsyncResult) Overlapped.Unpack(pOverlapped).AsyncResult;
asyncResult._numBytes = (int) numBytes;
if (!asyncResult._isWrite && (((errorCode == 0x6d) || (errorCode == 0xe9)) || (errorCode == 0xe8)))
{
errorCode = 0;
numBytes = 0;
}
if (errorCode == 0xea)
{
errorCode = 0;
asyncResult._isMessageComplete = false;
}
else
{
asyncResult._isMessageComplete = true;
}
asyncResult._errorCode = (int) errorCode;
asyncResult._completedSynchronously = false;
asyncResult._isComplete = true;
ManualResetEvent event2 = asyncResult._waitHandle;
if ((event2 != null) && !event2.Set())
{
System.IO.__Error.WinIOError();
}
AsyncCallback callback = asyncResult._userCallback;
if (callback != null)
{
callback(asyncResult);
}
}
示例8: Free
unsafe public static void Free (NativeOverlapped *nativeOverlappedPtr)
{
if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
throw new ArgumentNullException ("nativeOverlappedPtr");
Marshal.FreeHGlobal ((IntPtr) nativeOverlappedPtr);
}
示例9: Unpack
public static unsafe Overlapped Unpack(NativeOverlapped* nativeOverlappedPtr)
{
if (nativeOverlappedPtr == null)
{
throw new ArgumentNullException("nativeOverlappedPtr");
}
return OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr).m_overlapped;
}
示例10: HidDevice
public HidDevice(string devicePath)
{
_devicePath = devicePath;
_overlapped = new NativeOverlapped();
_overlapped.EventHandle = NativeInterface.CreateEvent(IntPtr.Zero, false, false, null);
_pinnedOverlapped = GCHandle.Alloc(_overlapped, GCHandleType.Pinned);
}
示例11: Eject
/// <summary>
///
/// </summary>
/// <param name="drive"></param>
public static void Eject(String drive)
{
using (SafeFileHandle hDevice = Win32.CreateFile(String.Format(@"\\.\{0}:", drive), FileAccess.Read, FileShare.Read, IntPtr.Zero, FileMode.Open, Win32.EFileAttributes.Normal, IntPtr.Zero))
{
UInt32 retVal = 0;
NativeOverlapped retOverlapped = new NativeOverlapped();
Win32.DeviceIoControl(hDevice, Win32.EIOControlCode.StorageEjectMedia, null, 0, null, 0, ref retVal, ref retOverlapped);
}
}
示例12: Callback
private void Callback(uint errorCode, uint numBytes, NativeOverlapped* pNOlap)
{
// Execute the task
_scheduler.TryExecuteTask(Task);
// Put this item back into the pool for someone else to use
var pool = _scheduler._availableWorkItems;
if(pool != null) pool.Add(this);
else Overlapped.Free(pNOlap);
}
示例13: SafeNativeOverlapped
public unsafe SafeNativeOverlapped(SafeCloseSocket socketHandle, NativeOverlapped* handle)
: this((IntPtr)handle)
{
_safeCloseSocket = socketHandle;
GlobalLog.Print("SafeNativeOverlapped#" + Logging.HashString(this) + "::ctor(socket#" + Logging.HashString(socketHandle) + ")");
#if DEBUG
_safeCloseSocket.AddRef();
#endif
}
示例14: SharedLockFile
public virtual int SharedLockFile( sqlite3_file pFile, long offset, long length )
{
Debug.Assert( length == SHARED_SIZE );
Debug.Assert( offset == SHARED_FIRST );
System.Threading.NativeOverlapped ovlp = new System.Threading.NativeOverlapped();
ovlp.OffsetLow = (int)offset;
ovlp.OffsetHigh = 0;
ovlp.EventHandle = IntPtr.Zero;
return LockFileEx( pFile.fs.Handle, LOCKFILE_FAIL_IMMEDIATELY, 0, (uint)length, 0, ref ovlp ) ? 1 : 0;
}
示例15: AsyncFSCallback
private static unsafe void AsyncFSCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
{
PipeAsyncResult asyncResult = (PipeAsyncResult) Overlapped.Unpack(pOverlapped).AsyncResult;
asyncResult._numBytes = (int) numBytes;
if (errorCode == 0x6dL)
{
errorCode = 0;
}
asyncResult._errorCode = (int) errorCode;
asyncResult._userCallback(asyncResult);
}