本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeWaitHandle类的典型用法代码示例。如果您正苦于以下问题:C# SafeWaitHandle类的具体用法?C# SafeWaitHandle怎么用?C# SafeWaitHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SafeWaitHandle类属于Microsoft.Win32.SafeHandles命名空间,在下文中一共展示了SafeWaitHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanlibWaitHandle
public CanlibWaitHandle(object we)
{
uint theHandle = (uint) we;
IntPtr pointer = new IntPtr((long) theHandle);
SafeWaitHandle swHandle = new SafeWaitHandle(pointer, true);
base.SafeWaitHandle = swHandle;
}
示例2: Semaphore
public Semaphore(int initialCount, int maximumCount, string name)
{
if (initialCount < 0)
{
throw new ArgumentOutOfRangeException("initialCount", SR.ArgumentOutOfRange_NeedNonNegNumRequired);
}
if (maximumCount < 1)
{
throw new ArgumentOutOfRangeException("maximumCount", SR.ArgumentOutOfRange_NeedPosNum);
}
if (initialCount > maximumCount)
{
throw new ArgumentException(SR.Argument_SemaphoreInitialMaximum);
}
if (null != name && MAX_PATH < name.Length)
{
throw new ArgumentException(SR.Argument_WaitHandleNameTooLong);
}
SafeWaitHandle myHandle = new SafeWaitHandle(Interop.mincore.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, (uint)(Interop.Constants.SemaphoreModifyState | Interop.Constants.Synchronize)), true);
if (myHandle.IsInvalid)
{
int errorCode = (int)Interop.mincore.GetLastError();
if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode)
throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
throw ExceptionFromCreationError(errorCode, name);
}
SafeWaitHandle = myHandle;
}
示例3: Thread
public static UInt64 Thread(SafeWaitHandle threadHandle)
{
UInt64 cycleTime;
if (!QueryThreadCycleTime(threadHandle, out cycleTime))
throw new Win32Exception();
return cycleTime;
}
示例4: Process
public static UInt64 Process(SafeWaitHandle processHandle)
{
UInt64 cycleTime;
if (!QueryProcessCycleTime(processHandle, out cycleTime))
throw new Win32Exception();
return cycleTime;
}
示例5: SetWaitableTimer
public static extern bool SetWaitableTimer(
SafeWaitHandle hTimer,
[In] ref long pDueTime,
int lPeriod,
IntPtr pfnCompletionRoutine,
IntPtr lpArgToCompletionRoutine,
bool fResume);
示例6: RegNotifyChangeKeyValue
public static extern int RegNotifyChangeKeyValue(
UIntPtr hKey,
bool bWatchSubtree,
uint dwNotifyFilter,
SafeWaitHandle hEvent,
bool fAsynchronous
);
示例7: SoundCaptureBase
public SoundCaptureBase(SoundCaptureDevice device)
{
this.device = device;
positionEvent = new AutoResetEvent(false);
positionEventHandle = positionEvent.SafeWaitHandle;
terminated = new ManualResetEvent(true);
}
示例8: CycleTime
/// <summary>
/// Initializes a new instance of the CycleTime class.
/// </summary>
/// <param name="trackingThreadTime">
/// True if you want to track the current thread time. False for the
/// process as a whole.
/// </param>
/// <param name="handle">
/// The handle to the process for observing.
/// </param>
private CycleTime(Boolean trackingThreadTime, SafeWaitHandle handle)
{
this.trackingThreadTime = trackingThreadTime;
this.handle = handle;
this.startCycleTime = this.trackingThreadTime
? Thread()
: Process(this.handle);
}
示例9: Process
/// <summary>
/// Retrieves the sum of the cycle time of all threads of the specified
/// process.
/// </summary>
public static ulong Process(SafeWaitHandle processHandle)
{
ulong cycleTime;
if (!QueryProcessCycleTime(processHandle, out cycleTime))
{
throw new Win32Exception();
}
return cycleTime;
}
示例10: Thread
/// <summary>
/// Retrieves the cycle time for the specified thread.
/// </summary>
public static ulong Thread(SafeWaitHandle threadHandle)
{
ulong cycleTime;
if (!QueryThreadCycleTime(threadHandle, out cycleTime))
{
throw new Win32Exception();
}
return cycleTime;
}
示例11: ResetEvent
public static bool ResetEvent (SafeWaitHandle handle)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return ResetEvent_internal (handle.DangerousGetHandle ());
} finally {
if (release)
handle.DangerousRelease ();
}
}
示例12: AbsoluteTimer
public WaitHandle AbsoluteTimer(DateTimeOffset expireAt)
{
var handle = CreateWaitableTimer(IntPtr.Zero, true, null);
var dueTime = expireAt.ToUniversalTime().ToFileTime();
SetWaitableTimer(handle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false);
var safeHandle = new SafeWaitHandle(handle, true);
return new TimerWaitHandle(safeHandle);
}
示例13: ProcessInfo
public ProcessInfo(
Process ps,
ProcessInformation psi)
{
if (null == ps)
{
throw new ArgumentNullException("ps");
}
this.ps = ps;
this.mainThreadHandle = new SafeWaitHandle(
psi.hThread,
true);
}
示例14: ByteRangeDownloader
internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHandle eventHandle)
: this(requestedUri, eventHandle)
{
if (tempFileName == null)
{
throw new ArgumentNullException("tempFileName");
}
if (tempFileName.Length <= 0)
{
throw new ArgumentException(SR.Get(SRID.InvalidTempFileName), "tempFileName");
}
_tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
}
示例15: EventWaitHandle
public EventWaitHandle(bool initialState, EventResetMode mode, string name)
{
if(null != name && System.IO.Path.MAX_PATH < name.Length)
{
throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
}
Contract.EndContractBlock();
SafeWaitHandle _handle = null;
#if MONO
int errorCode;
#endif
switch(mode)
{
case EventResetMode.ManualReset:
#if MONO
_handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (true, initialState, name, out errorCode), true);
#else
_handle = Win32Native.CreateEvent(null, true, initialState, name);
#endif
break;
case EventResetMode.AutoReset:
#if MONO
_handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (false, initialState, name, out errorCode), true);
#else
_handle = Win32Native.CreateEvent(null, false, initialState, name);
#endif
break;
default:
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
};
if (_handle.IsInvalid)
{
#if !MONO
int errorCode = Marshal.GetLastWin32Error();
#endif
_handle.SetHandleAsInvalid();
if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name));
__Error.WinIOError(errorCode, name);
}
SetHandleInternal(_handle);
}