2using System.Collections.Generic;
18 bool m_bOwnOriginal =
true;
19 WaitHandle m_hOriginalCancel =
null;
20 List<Tuple<WaitHandle, bool, string>> m_rgCancel =
new List<Tuple<WaitHandle, bool, string>>();
21 WaitHandle[] m_rgHandles =
new WaitHandle[1];
22 string m_strName =
null;
23 object m_syncObj =
new object();
30 m_hOriginalCancel =
new EventWaitHandle(
false, EventResetMode.ManualReset, m_strName);
41 if (strGlobalName ==
null)
43 m_hOriginalCancel =
new EventWaitHandle(
false, EventResetMode.ManualReset, m_strName);
47 m_strName = strGlobalName;
48 m_hOriginalCancel = EventWaitHandle.OpenExisting(strGlobalName,
System.Security.AccessControl.EventWaitHandleRights.Synchronize |
System.Security.AccessControl.EventWaitHandleRights.Modify);
60 m_hOriginalCancel =
new EventWaitHandle(
false, EventResetMode.ManualReset, m_strName);
61 m_rgCancel.Add(
new Tuple<WaitHandle, bool, string>(evtCancel.m_hOriginalCancel,
false, evtCancel.
Name));
65 private void setHandles()
69 m_rgHandles =
new WaitHandle[m_rgCancel.Count + 1];
70 m_rgHandles[0] = m_hOriginalCancel;
72 for (
int i = 0; i < m_rgCancel.Count; i++)
74 m_rgHandles[i + 1] = m_rgCancel[i].Item1;
85 EventWaitHandle evtWait = EventWaitHandle.OpenExisting(strName,
System.Security.AccessControl.EventWaitHandleRights.Synchronize |
System.Security.AccessControl.EventWaitHandleRights.Modify);
89 m_rgCancel.Add(
new Tuple<WaitHandle, bool, string>(evtWait,
true, strName));
102 m_rgCancel.Add(
new Tuple<WaitHandle, bool, string>(evtCancel.m_hOriginalCancel,
false, evtCancel.
Name));
115 m_rgCancel.Add(
new Tuple<WaitHandle, bool, string>(evtCancel,
false,
null));
127 return Contains(evt.m_hOriginalCancel);
137 foreach (Tuple<WaitHandle, bool, string> item
in m_rgCancel)
139 if (item.Item1 == evt)
153 foreach (Tuple<WaitHandle, bool, string> item
in m_rgCancel)
155 if (item.Item3 == strName)
170 bool bResult =
false;
172 for (
int i = 0; i < m_rgCancel.Count; i++)
174 if (m_rgCancel[i].Item3 == strName)
183 if (m_rgCancel[nIdx].Item2)
184 m_rgCancel[nIdx].Item1.Dispose();
186 m_rgCancel.RemoveAt(nIdx);
203 bool bResult =
false;
205 for (
int i = 0; i < m_rgCancel.Count; i++)
207 if (m_rgCancel[i].Item1 == evtCancel.m_hOriginalCancel)
216 if (m_rgCancel[nIdx].Item2)
217 m_rgCancel[nIdx].Item1.Dispose();
219 m_rgCancel.RemoveAt(nIdx);
235 bool bResult =
false;
239 for (
int i = 0; i < m_rgCancel.Count; i++)
241 if (m_rgCancel[i].Item1 == evtCancel)
250 m_rgCancel.RemoveAt(nIdx);
264 get {
return m_strName; }
272 if (m_hOriginalCancel is EventWaitHandle)
273 ((EventWaitHandle)m_hOriginalCancel).Set();
281 if (m_hOriginalCancel is EventWaitHandle)
282 ((EventWaitHandle)m_hOriginalCancel).Reset();
292 if (WaitHandle.WaitAny(
Handles, nMs) == WaitHandle.WaitTimeout)
312 #region IDisposable Support
318 protected virtual void Dispose(
bool disposing)
320 if (m_bOwnOriginal && m_hOriginalCancel !=
null)
322 m_hOriginalCancel.Dispose();
323 m_hOriginalCancel =
null;
326 foreach (Tuple<WaitHandle, bool, string> item
in m_rgCancel)
329 item.Item1.Dispose();
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
CancelEvent(CancelEvent evtCancel)
Create a new Cancel Event and add another to this ones overrides.
void Reset()
Resets the event clearing any signaled state.
bool Contains(string strName)
Check to see if the named cancel event has already been added.
CancelEvent(string strGlobalName)
The CancelEvent constructor that accepts a global name.
WaitHandle[] Handles
Returns the internal wait handle of the CancelEvent.
bool RemoveCancelOverride(string strName)
Remove a new cancel override.
bool RemoveCancelOverride(WaitHandle evtCancel)
Remove a new cancel override.
virtual void Dispose(bool disposing)
Releases all resources used by the CancelEvent.
void AddCancelOverride(string strName)
Add a new cancel override.
string Name
Return the name of the cancel event.
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
CancelEvent()
The CancelEvent constructor.
void Set()
Sets the event to the signaled state.
bool RemoveCancelOverride(CancelEvent evtCancel)
Remove a new cancel override.
void AddCancelOverride(CancelEvent evtCancel)
Add a new cancel override.
void Dispose()
Releases all resources used by the CancelEvent.
void AddCancelOverride(WaitHandle evtCancel)
Add a new cancel override.
bool Contains(CancelEvent evt)
Check to see if the cancel event has already been added.
bool Contains(WaitHandle evt)
Check to see if the cancel event has already been added.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.