本文整理汇总了C#中EventResetMode类的典型用法代码示例。如果您正苦于以下问题:C# EventResetMode类的具体用法?C# EventResetMode怎么用?C# EventResetMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventResetMode类属于命名空间,在下文中一共展示了EventResetMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
switch(mode)
{
case EventResetMode.ManualReset:
_handle = Win32Native.CreateEvent(null, true, initialState, name);
break;
case EventResetMode.AutoReset:
_handle = Win32Native.CreateEvent(null, false, initialState, name);
break;
default:
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
};
if (_handle.IsInvalid)
{
int errorCode = Marshal.GetLastWin32Error();
_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);
}
示例2: IsManualReset
private static bool IsManualReset (EventResetMode mode)
{
if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) {
throw new ArgumentException ("mode");
}
return mode == EventResetMode.ManualReset;
}
示例3: EventWaitHandle
public EventWaitHandle(bool initialState, EventResetMode mode, string name)
{
if ((name != null) && (260 < name.Length))
{
throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
}
SafeWaitHandle handle = null;
switch (mode)
{
case EventResetMode.AutoReset:
handle = Win32Native.CreateEvent(null, false, initialState, name);
break;
case EventResetMode.ManualReset:
handle = Win32Native.CreateEvent(null, true, initialState, name);
break;
default:
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name }));
}
if (handle.IsInvalid)
{
int errorCode = Marshal.GetLastWin32Error();
handle.SetHandleAsInvalid();
if (((name != null) && (name.Length != 0)) && (6 == errorCode))
{
throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name }));
}
__Error.WinIOError(errorCode, "");
}
base.SetHandleInternal(handle);
}
示例4: EventWaitHandle
public EventWaitHandle (bool initialState, EventResetMode mode,
string name, out bool createdNew,
EventWaitHandleSecurity eventSecurity)
{
bool manual = IsManualReset (mode);
Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
}
示例5: EventWaitHandle
public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew)
{
IntPtr ptr = CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name);
if (ptr.Equals(IntPtr.Zero))
{
throw new ApplicationException("Cannot create " + name);
}
createdNew = Marshal.GetLastWin32Error() != 0xb7;
Handle = ptr;
}
示例6: OpenOrCreate
/// <summary>
/// Close any open handles with <paramref name="name"/> and open a new one.
/// </summary>
/// <param name="name">The handle name.</param>
/// <param name="initialState">Initial state.</param>
/// <param name="mode">The mode.</param>
/// <returns>The new EventWaitHandle created.</returns>
public static EventWaitHandle OpenOrCreate(string name, bool initialState, EventResetMode mode)
{
try
{
EventWaitHandle.OpenExisting(name).Close();
}
catch (WaitHandleCannotBeOpenedException) { }
return new EventWaitHandle(initialState, mode, name);
}
示例7: EventEx
/// <summary>
/// Default Constructor
/// </summary>
/// <param name="eventName">name of the event to distinguish</param>
public EventEx(String eventName = null)
: base()
{
m_eventResetMode=EventResetMode.AutoReset;
m_isInitialRaised=true;
m_name=eventName;
if (m_name == null)
m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
else
m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
}
示例8: EventWaitHandleEx
public EventWaitHandleEx(bool initialState, EventResetMode mode, string name, out bool createdNew)
{
var handle = NativeMethods.CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name);
if (handle == IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
createdNew = Marshal.GetLastWin32Error() != ERROR_ALREADY_EXISTS;
Handle = handle;
}
示例9: EventEx
/// <summary>
/// Default Constructor
/// </summary>
/// <param name="eventName">name of the event to distinguish</param>
public EventEx()
: base()
{
m_eventResetMode = EventResetMode.AutoReset;
m_isInitialRaised=true;
if (m_eventResetMode == EventResetMode.AutoReset)
m_event = new AutoResetEvent(m_isInitialRaised);
else
{
m_event = new ManualResetEvent(m_isInitialRaised);
}
}
示例10: Create
public static bool Create(string name, EventResetMode mode, out EventWaitHandle signal)
{
var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize |
EventWaitHandleRights.Modify, AccessControlType.Allow);
var security = new EventWaitHandleSecurity();
security.AddAccessRule(rule);
bool created;
signal = new EventWaitHandle(false, mode, @"Global\" + name, out created, security);
return created;
}
示例11: Ctor_StateModeNameCreatedNew_Windows
public void Ctor_StateModeNameCreatedNew_Windows(bool initialState, EventResetMode mode)
{
string name = Guid.NewGuid().ToString("N");
bool createdNew;
using (var ewh = new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew))
{
Assert.True(createdNew);
using (new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew))
{
Assert.False(createdNew);
}
}
}
示例12: EventWaitHandle
public EventWaitHandle(bool initialState, EventResetMode mode, string name)
{
if (null != name)
{
if (((int)Interop.Constants.MaxPath) < name.Length)
{
throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name));
}
}
Contract.EndContractBlock();
uint eventFlags = initialState ? (uint)Interop.Constants.CreateEventInitialSet : 0;
IntPtr unsafeHandle;
switch (mode)
{
case EventResetMode.ManualReset:
eventFlags |= (uint)Interop.Constants.CreateEventManualReset;
break;
case EventResetMode.AutoReset:
break;
default:
throw new ArgumentException(SR.Format(SR.Argument_InvalidFlag, name));
};
unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess);
int errorCode = (int)Interop.mincore.GetLastError();
SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true);
if (_handle.IsInvalid)
{
_handle.SetHandleAsInvalid();
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 = _handle;
}
示例13: PingPong
public void PingPong(EventResetMode mode)
{
// Create names for the two events
string outboundName = Guid.NewGuid().ToString("N");
string inboundName = Guid.NewGuid().ToString("N");
// Create the two events and the other process with which to synchronize
using (var inbound = new EventWaitHandle(true, mode, inboundName))
using (var outbound = new EventWaitHandle(false, mode, outboundName))
using (var remote = RemoteInvoke(PingPong_OtherProcess, mode.ToString(), outboundName, inboundName))
{
// Repeatedly wait for one event and then set the other
for (int i = 0; i < 10; i++)
{
Assert.True(inbound.WaitOne(FailWaitTimeoutMilliseconds));
if (mode == EventResetMode.ManualReset)
{
inbound.Reset();
}
outbound.Set();
}
}
}
示例14: Ctor_StateMode
public void Ctor_StateMode(bool initialState, EventResetMode mode)
{
using (var ewh = new EventWaitHandle(initialState, mode))
Assert.Equal(initialState, ewh.WaitOne(0));
}
示例15: IsManualReset
private bool IsManualReset (EventResetMode mode)
{
if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset))
throw new ArgumentException ("mode");
return (mode == EventResetMode.ManualReset);
}