Files
Dec2017-Script-Dump/mscorlib/System/Threading/RegisteredWaitHandle.cs
T
2026-06-04 11:42:34 +02:00

130 lines
3.7 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace System.Threading
{
/// <summary>Represents a handle that has been registered when calling <see cref="M:System.Threading.ThreadPool.RegisterWaitForSingleObject(System.Threading.WaitHandle,System.Threading.WaitOrTimerCallback,System.Object,System.UInt32,System.Boolean)" />. This class cannot be inherited.</summary>
/// <filterpriority>2</filterpriority>
// Token: 0x0200061B RID: 1563
[ComVisible(true)]
public sealed class RegisteredWaitHandle : MarshalByRefObject
{
// Token: 0x06003921 RID: 14625 RVA: 0x000C52F8 File Offset: 0x000C34F8
internal RegisteredWaitHandle(WaitHandle waitObject, WaitOrTimerCallback callback, object state, TimeSpan timeout, bool executeOnlyOnce)
{
this._waitObject = waitObject;
this._callback = callback;
this._state = state;
this._timeout = timeout;
this._executeOnlyOnce = executeOnlyOnce;
this._finalEvent = null;
this._cancelEvent = new ManualResetEvent(false);
this._callsInProcess = 0;
this._unregistered = false;
}
// Token: 0x06003922 RID: 14626 RVA: 0x000C5354 File Offset: 0x000C3554
internal void Wait(object state)
{
try
{
WaitHandle[] array = new WaitHandle[] { this._waitObject, this._cancelEvent };
do
{
int num = WaitHandle.WaitAny(array, this._timeout, false);
if (!this._unregistered)
{
lock (this)
{
this._callsInProcess++;
}
ThreadPool.QueueUserWorkItem(new WaitCallback(this.DoCallBack), num == 258);
}
}
while (!this._unregistered && !this._executeOnlyOnce);
}
catch
{
}
lock (this)
{
this._unregistered = true;
if (this._callsInProcess == 0 && this._finalEvent != null)
{
NativeEventCalls.SetEvent_internal(this._finalEvent.Handle);
}
}
}
// Token: 0x06003923 RID: 14627 RVA: 0x000C5484 File Offset: 0x000C3684
private void DoCallBack(object timedOut)
{
if (this._callback != null)
{
this._callback(this._state, (bool)timedOut);
}
lock (this)
{
this._callsInProcess--;
if (this._unregistered && this._callsInProcess == 0 && this._finalEvent != null)
{
NativeEventCalls.SetEvent_internal(this._finalEvent.Handle);
}
}
}
/// <summary>Cancels a registered wait operation issued by the <see cref="M:System.Threading.ThreadPool.RegisterWaitForSingleObject(System.Threading.WaitHandle,System.Threading.WaitOrTimerCallback,System.Object,System.UInt32,System.Boolean)" /> method.</summary>
/// <returns>true if the function succeeds; otherwise, false.</returns>
/// <param name="waitObject">The <see cref="T:System.Threading.WaitHandle" /> to be signaled. </param>
/// <filterpriority>2</filterpriority>
// Token: 0x06003924 RID: 14628 RVA: 0x000C5524 File Offset: 0x000C3724
[ComVisible(true)]
public bool Unregister(WaitHandle waitObject)
{
bool flag;
lock (this)
{
if (this._unregistered)
{
flag = false;
}
else
{
this._finalEvent = waitObject;
this._unregistered = true;
this._cancelEvent.Set();
flag = true;
}
}
return flag;
}
// Token: 0x04001703 RID: 5891
private WaitHandle _waitObject;
// Token: 0x04001704 RID: 5892
private WaitOrTimerCallback _callback;
// Token: 0x04001705 RID: 5893
private TimeSpan _timeout;
// Token: 0x04001706 RID: 5894
private object _state;
// Token: 0x04001707 RID: 5895
private bool _executeOnlyOnce;
// Token: 0x04001708 RID: 5896
private WaitHandle _finalEvent;
// Token: 0x04001709 RID: 5897
private ManualResetEvent _cancelEvent;
// Token: 0x0400170A RID: 5898
private int _callsInProcess;
// Token: 0x0400170B RID: 5899
private bool _unregistered;
}
}