本文整理汇总了C#中System.Threading.AutoResetEvent.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.AutoResetEvent.Close方法的具体用法?C# System.Threading.AutoResetEvent.Close怎么用?C# System.Threading.AutoResetEvent.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.AutoResetEvent
的用法示例。
在下文中一共展示了System.Threading.AutoResetEvent.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GlibSync
// Sync up with the GLib thread. Should be called after the
// name, role, or parent are changed in UiaAtkBridge when
// checking for events, since we defer to an idle
// handler to call atk to avoid deadlock when atk
// emits signals. Called by RunInGuiThread in
// UiaAtkBridge.
public static void GlibSync ()
{
System.Threading.AutoResetEvent sync = new System.Threading.AutoResetEvent (false);
GLib.Timeout.Add (0, new GLib.TimeoutHandler (delegate {
sync.Set ();
return false;
}));
sync.WaitOne ();
sync.Close ();
}
示例2: TimedWait
public bool TimedWait(int timeout)
{
//
// Push an event onto the wait queue. The event is removed from the queue if
// Notify or NotifyAll is called, otherwise we have to remove it explicitly.
// We use a LinkedListNode here because we can remove it in O(1) time.
//
System.Threading.EventWaitHandle e = new System.Threading.AutoResetEvent(false);
LinkedListNode<System.Threading.EventWaitHandle> node =
new LinkedListNode<System.Threading.EventWaitHandle>(e);
_waitQueue.AddLast(node);
//
// Preserve the lock count until we reaquire the lock.
//
int lockCount = _lockCount;
_lockCount = 0;
//
// Fully release the lock.
//
for(int i = 0; i < lockCount; ++i)
{
_mutex.ReleaseMutex();
}
//
// Wait for the event to be set or the timeout to expire.
//
bool b = e.WaitOne(timeout, false);
//
// NOTE: There's a race here if the timeout expired: another thread could
// acquire the lock and call Notify. In turn, Notify could remove this event
// from the wait queue and set it. Now we have a situation where the timeout
// technically expired but the event was actually set. If we still treat this
// as an expired timeout then the Notify will have been lost.
//
// The timeout isn't precise because we also have to wait an indeterminate
// time to reacquire the lock. The simplest solution therefore is to check
// the event one more time after acquiring the lock - if it's set now, we
// act as if the wait succeeded. This might be an issue for a general-purpose
// monitor implementation, but for Ice it shouldn't cause any problems.
//
//
// Reacquire the lock the same number of times.
//
for(int i = 0; i < lockCount; ++i)
{
_mutex.WaitOne();
}
_lockCount = lockCount;
//
// In the case of a timeout, check the event one more time to work around the
// race condition described above.
//
if(!b)
{
b = e.WaitOne(0, false);
}
//
// If our event was not signaled, we need to remove it from the wait queue.
//
if(!b)
{
Debug.Assert(node.List != null); // The node must still be in the wait queue.
_waitQueue.Remove(node);
}
//
// It is safe to close the event now because no other thread will use it.
//
e.Close();
return b;
}
示例3: Wait
public void Wait()
{
//
// Push an event onto the wait queue. Eventually, a call to Notify or NotifyAll
// will remove the event from the wait queue and signal it.
//
System.Threading.EventWaitHandle e = new System.Threading.AutoResetEvent(false);
_waitQueue.AddLast(e);
//
// Preserve the lock count until we reaquire the lock.
//
int lockCount = _lockCount;
_lockCount = 0;
//
// Fully release the lock.
//
for(int i = 0; i < lockCount; ++i)
{
_mutex.ReleaseMutex();
}
//
// Wait for the event to be set.
//
e.WaitOne();
//
// Reacquire the lock the same number of times.
//
for(int i = 0; i < lockCount; ++i)
{
_mutex.WaitOne();
}
_lockCount = lockCount;
//
// It is safe to close the event now because no other thread will use it (Notify
// or NotifyAll has already removed the event from the wait queue).
//
e.Close();
}
示例4: GetObjectName
private string GetObjectName(Primitive prim, int distance)
{
string name = "Loading...";
string ownerName = "Loading...";
if (prim.Properties != null)
{
name = prim.Properties.Name;
// prim.Properties.GroupID is the actual group when group owned, not prim.GroupID
if (UUID.Zero == prim.Properties.OwnerID &&
PrimFlags.ObjectGroupOwned == (prim.Flags & PrimFlags.ObjectGroupOwned) &&
UUID.Zero != prim.Properties.GroupID)
{
System.Threading.AutoResetEvent nameReceivedSignal = new System.Threading.AutoResetEvent(false);
EventHandler<GroupNamesEventArgs> cbGroupName = new EventHandler<GroupNamesEventArgs>(
delegate(object sender, GroupNamesEventArgs e)
{
if (e.GroupNames.ContainsKey(prim.Properties.GroupID))
{
e.GroupNames.TryGetValue(prim.Properties.GroupID, out ownerName);
if (string.IsNullOrEmpty(ownerName))
ownerName = "Loading...";
if (null != nameReceivedSignal)
nameReceivedSignal.Set();
}
});
client.Groups.GroupNamesReply += cbGroupName;
client.Groups.RequestGroupName(prim.Properties.GroupID);
nameReceivedSignal.WaitOne(5000, false);
nameReceivedSignal.Close();
client.Groups.GroupNamesReply -= cbGroupName;
}
else
ownerName = instance.Names.Get(prim.Properties.OwnerID);
}
if (prim.ParentID == client.Self.LocalID)
{
return string.Format("{0} attached to {1}", name, prim.PrimData.AttachmentPoint.ToString());
}
else if (ownerName != "Loading...")
{
return String.Format("{0} ({1}m) owned by {2}", name, distance, ownerName);
}
else
{
return String.Format("{0} ({1}m)", name, distance);
}
}