本文整理汇总了C#中System.Threading.RegisteredWaitHandle类的典型用法代码示例。如果您正苦于以下问题:C# RegisteredWaitHandle类的具体用法?C# RegisteredWaitHandle怎么用?C# RegisteredWaitHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegisteredWaitHandle类属于System.Threading命名空间,在下文中一共展示了RegisteredWaitHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallbackInfo
public CallbackInfo(Action<RawBusMessage, Exception> callback, Type replyType, ManualResetEvent ev, RegisteredWaitHandle handle)
{
_callback = callback;
_replyType = replyType;
_ev = ev;
_handle = handle;
}
示例2: SetTimer
public void SetTimer(int MillisecondTimeout, TimeElapsedHandler CB)
{
lock(TimeoutList)
{
long Ticks = DateTime.Now.AddMilliseconds(MillisecondTimeout).Ticks;
while(TimeoutList.ContainsKey(Ticks)==true)
{
++Ticks;
}
TimeoutList.Add(Ticks,CB);
if(TimeoutList.Count==1)
{
// First Entry
mre.Reset();
handle = ThreadPool.RegisterWaitForSingleObject(
mre,
WOTcb,
null,
MillisecondTimeout,
true);
}
else
{
mre.Set();
}
}
}
示例3: HeartbeatSender
public HeartbeatSender(TimeSpan period, RestTarget heartbeatRest)
{
_period = period;
_heartbeatRest = heartbeatRest;
_registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(_disposeEvent, SendHeartBeats, null, _period, false);
}
示例4: unregister
public bool unregister()
{
ManualResetEvent callbackThreadComplete = new ManualResetEvent(false);
int timeToWait = 5000; //milliseconds
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
if (this.sessionRegisteredWait != null)
{
if (this.sessionRegisteredWait.Unregister(callbackThreadComplete))
{
Console.WriteLine("waiting on succesful unregister");
callbackThreadComplete.WaitOne(timeToWait);
}
}
this.sessionRegisteredWait = null;
long elapsed = sw.ElapsedMilliseconds;
Console.WriteLine("Elapsed: {0} millisec", elapsed);
if (elapsed >= timeToWait)
{
Console.WriteLine("Error. Callback was not signaled");
return false;
}
else
{
Console.WriteLine("Success");
return true;
}
}
示例5: BufferRecorder
/// <summary>
/// create a buffer recorder for a stream
/// </summary>
/// <param name="number">ordinal for diagnostics</param>
/// <param name="streamID">the stream I'm for</param>
public BufferRecorder( int number, int streamID )
{
isAvailable = true;
this.number = number;
indices = new Index[Constants.IndexCapacity];
currentIndex = 0;
buffer = new byte[Constants.BufferSize];
this.streamID = streamID;
// setup the db writer thread
canSave = new AutoResetEvent(false);
// The BufferTimeout feature is "turned off" so that the buffer won't automatically write to disk sporadically.
// This is a nice safety feature we should try to turn back on. It was turned off because it was saving data
// and causing frames to be written out of order in the DB.
waitHandle = ThreadPool.RegisterWaitForSingleObject( canSave,
new WaitOrTimerCallback(InitiateSave),
this,
Constants.BufferTimeout,
false);
Thread.Sleep(50); // Allows for the Registration to occur & get setup
// Without the Sleep, if we walk into a massive session with lots of data moving, we get slammed & can't keep up.
}
示例6: BufferPlayer
/// <summary>
/// set ourselves up, we are pretty dumb so need to be told who we're sending for
/// and where to get our data from, and when to start sending..
/// </summary>
/// <remarks>
/// It seems that we don't use maxFrameSize any more. hmm. Remove it?
/// </remarks>
public BufferPlayer(int streamID, int maxFrameSize, int maxFrameCount, int maxBufferSize)
{
Debug.Assert( maxBufferSize >= maxFrameSize ); // just for kicks...
buffer = new BufferChunk( maxBufferSize );
indices = new Index[maxFrameCount+1]; // Pri3: why is this "+1" here? (DO NOT REMOVE YET)
this.populating = false;
this.streamOutOfData = false;
this.streamID = streamID;
this.currentIndex = 0;
this.indexCount = 0;
this.startingTick = 0;
canPopulate = new AutoResetEvent(false);
// pool a thread to re-populate ourselves
waitHandle = ThreadPool.RegisterWaitForSingleObject(
canPopulate,
new WaitOrTimerCallback( InitiatePopulation ),
this,
-1, // never timeout to perform a population
false );
}
示例7: BeginRunOnTimer
private void BeginRunOnTimer(object state, bool isTimeout)
{
//Wait for this race condition to satisfy
while (m_registeredHandle == null)
;
m_registeredHandle.Unregister(null);
m_registeredHandle = null;
OnRunning();
}
示例8: QueueLogWriter
private volatile int flushIsRunning = 0; // 0 = false, 1 = true
#endregion Fields
#region Constructors
public QueueLogWriter()
{
File.Delete(aof);
fileStream = new FileStream(aof, FileMode.OpenOrCreate, FileAccess.Write);
flushSignalWaitHandle
= ThreadPool.RegisterWaitForSingleObject(flushSignal, (state, timedOut) => Flush(), null, -1, false);
flushSignal.Set(); // signal to start pump right away
}
示例9: EventsQueue
public EventsQueue(Boolean bufferedOutput, Int32 autoFlushPeriod,
Action<IEnumerable<EventRecord>> flushAction)
{
this.bufferedOutput = bufferedOutput;
this.flushAction = flushAction;
this.syncObject = new Object();
this.eventsList = new List<EventRecord>();
this.flushEvent = new AutoResetEvent(false);
this.registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(
this.flushEvent, FlushEventSignaledCallback, null, autoFlushPeriod * 1000, false);
}
示例10: RegisterTimeout
public void RegisterTimeout(TimeSpan interval, Action callback)
{
lock (m_syncRoot)
{
if (m_callback != null)
throw new Exception("Duplicate calls are not permitted");
m_callback = callback;
m_resetEvent = new ManualResetEvent(false);
m_registeredHandle = ThreadPool.RegisterWaitForSingleObject(m_resetEvent, BeginRun, null, interval, true);
}
}
示例11: InitializeConnectionTimeoutHandler
private static void InitializeConnectionTimeoutHandler()
{
_socketTimeoutDelegate = new WaitOrTimerCallback(TimeoutConnections);
_socketTimeoutWaitHandle = new AutoResetEvent(false);
_registeredWaitHandle =
ThreadPool.UnsafeRegisterWaitForSingleObject(
_socketTimeoutWaitHandle,
_socketTimeoutDelegate,
"IpcConnectionTimeout",
_socketTimeoutPollTime,
true); // execute only once
} // InitializeSocketTimeoutHandler
示例12: CancelAsyncOperation
public unsafe void CancelAsyncOperation()
{
this.rootedHolder.ThisHolder = null;
if (this.registration != null)
{
this.registration.Unregister(null);
this.registration = null;
}
this.bufferPtr = null;
this.bufferHolder[0] = dummyBuffer;
this.pendingCallback = null;
}
示例13: TimeoutSockets
private static void TimeoutSockets(object state, bool wasSignalled)
{
DateTime utcNow = DateTime.UtcNow;
lock (_connections)
{
foreach (DictionaryEntry entry in _connections)
{
((RemoteConnection) entry.Value).TimeoutSockets(utcNow);
}
}
_registeredWaitHandle.Unregister(null);
_registeredWaitHandle = ThreadPool.UnsafeRegisterWaitForSingleObject(_socketTimeoutWaitHandle, _socketTimeoutDelegate, "TcpChannelSocketTimeout", _socketTimeoutPollTime, true);
}
示例14: Log
static Log() {
_useDiagnostic = System.Diagnostics.Debugger.IsAttached;
try { int window_height = Console.WindowHeight; _useConsole = true; }
catch { _useConsole = false; }
if(!Directory.Exists("../log")) {
Directory.CreateDirectory("../log");
}
useFile = true;
_lfMask = "../log/{0}_" + Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location) + ".log";
_records = new System.Collections.Concurrent.ConcurrentQueue<LogRecord>();
_kickEv = new AutoResetEvent(false);
_wh = ThreadPool.RegisterWaitForSingleObject(_kickEv, Process, null, -1, false);
}
示例15: Cancel
public void Cancel()
{
lock (m_syncRoot)
{
if (m_registeredHandle != null)
{
m_registeredHandle.Unregister(null);
m_resetEvent.Dispose();
m_resetEvent = null;
m_registeredHandle = null;
m_callback = null;
}
}
}