本文整理汇总了C#中WaitOrTimerCallback类的典型用法代码示例。如果您正苦于以下问题:C# WaitOrTimerCallback类的具体用法?C# WaitOrTimerCallback怎么用?C# WaitOrTimerCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WaitOrTimerCallback类属于命名空间,在下文中一共展示了WaitOrTimerCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisteredWaitHandle
internal RegisteredWaitHandle (WaitHandle waitObject, WaitOrTimerCallback callback,
object cbState, int timeout, bool executeOnlyOnce)
{
this.waitObject = waitObject;
this.callback = callback;
this.cbState = cbState;
this.timeout = timeout;
this.executeOnlyOnce = executeOnlyOnce;
StWaitable waitable;
if ((waitable = waitObject.waitable) == null) {
/*
* Either we're dealing with a disposed wait handle
* or with some other derived class.
*/
UnparkCallback (StParkStatus.Inflated);
return;
}
cbparker = new CbParker (UnparkCallback, false, true);
int ignored = 0;
waitBlock = waitable._WaitAnyPrologue (cbparker, StParkStatus.Success, ref hint, ref ignored);
state = ACTIVE;
int ws = cbparker.EnableCallback (timeout);
if (ws != StParkStatus.Pending) {
UnparkCallback (ws);
}
}
示例2: OverlappedContext
public OverlappedContext()
{
if (OverlappedContext.completeCallback == null)
{
OverlappedContext.completeCallback = Fx.ThunkCallback(new IOCompletionCallback(CompleteCallback));
}
if (OverlappedContext.eventCallback == null)
{
OverlappedContext.eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(EventCallback));
}
if (OverlappedContext.cleanupCallback == null)
{
OverlappedContext.cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(CleanupCallback));
}
this.bufferHolder = new object[] { OverlappedContext.dummyBuffer };
this.overlapped = new Overlapped();
this.nativeOverlapped = this.overlapped.UnsafePack(OverlappedContext.completeCallback, this.bufferHolder);
// When replacing the buffer, we need to provoke the CLR to fix up the handle of the pin.
this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*)nativeOverlapped +
(IntPtr.Size == 4 ? HandleOffsetFromOverlapped32 : HandleOffsetFromOverlapped64)));
this.pinnedTarget = this.pinnedHandle.Target;
// Create the permanently rooted holder and put it in the Overlapped.
this.rootedHolder = new RootedHolder();
this.overlapped.AsyncResult = rootedHolder;
}
示例3: SafeTimer
public SafeTimer()
{
WaitFlag = false;
timeout = 0;
WOTcb = new WaitOrTimerCallback(HandleTimer);
OpenSource.Utilities.InstanceTracker.Add(this);
}
示例4: _ThreadPoolWaitOrTimerCallback
internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
{
this._waitOrTimerCallback = waitOrTimerCallback;
this._state = state;
if (compressStack && !ExecutionContext.IsFlowSuppressed())
{
this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:_ThreadPoolWaitOrTimerCallback.cs
示例5: _ThreadPoolWaitOrTimerCallback
internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
{
this._waitOrTimerCallback = waitOrTimerCallback;
this._state = state;
if (compressStack && !ExecutionContext.IsFlowSuppressed())
{
this._executionContext = ExecutionContext.Capture(ref stackMark);
ExecutionContext.ClearSyncContext(this._executionContext);
}
}
示例6: 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
示例7: RegisteredWaitHandle
internal RegisteredWaitHandle (WaitHandle waitObject, WaitOrTimerCallback callback, object state, TimeSpan timeout, bool executeOnlyOnce)
{
_waitObject = waitObject;
_callback = callback;
_state = state;
_timeout = timeout;
_executeOnlyOnce = executeOnlyOnce;
_finalEvent = null;
_cancelEvent = new ManualResetEvent (false);
_callsInProcess = 0;
_unregistered = false;
}
示例8: Page_Load
/**
* we lay the groundwork for further async calls in page load
*/
public void Page_Load( Object sender, EventArgs e )
{
Response.Write("page load entered\n");
// we set the timeout to something really long, so that .net
// won't time out our request - we want long running
TimeSpan timeOut = new TimeSpan( 1, 0, 0, 0, 0 );
this.AsyncTimeout = timeOut;
// fire up a delegate that invokes the function that we
// ultimately want to call
m_doAsyncDelegate = new DoAsyncDelegate( DoAsync );
// this is a hack to get some browsers to display something
// we write some data to fill the buffer or something
for( int i=0; i < 1000; i++ )
{
Response.Write("<span></span>");
}
Response.Flush();
// here we set up a periodic poller using threadpool. the
// basic idea is that we have a call back that is periodically
// visited by a threadpool thread. This really isn't a poll,
// and is not really done by the threadpool, we use an autoresetevent
m_wtCallback = new WaitOrTimerCallback( Callback );
AutoResetEvent are = new AutoResetEvent( false );
ThreadPool.RegisterWaitForSingleObject( are, m_wtCallback, null, 1000, false );
// the meat of getting this all to work revolves around the
// registration of handlers for begin and end
RegisterAsyncTask(
new PageAsyncTask(
new BeginEventHandler( this.BeginLoad ),
new EndEventHandler( this.EndLoad ),
null, null, false )
);
}
示例9: OverlappedContext
public unsafe OverlappedContext()
{
if (completeCallback == null)
{
completeCallback = Fx.ThunkCallback(new IOCompletionCallback(OverlappedContext.CompleteCallback));
}
if (eventCallback == null)
{
eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.EventCallback));
}
if (cleanupCallback == null)
{
cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.CleanupCallback));
}
this.bufferHolder = new object[] { dummyBuffer };
this.overlapped = new Overlapped();
this.nativeOverlapped = this.overlapped.UnsafePack(completeCallback, this.bufferHolder);
this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*) (this.nativeOverlapped + (((IntPtr.Size == 4) ? -4 : -3) * sizeof(IntPtr)))));
this.pinnedTarget = this.pinnedHandle.Target;
this.rootedHolder = new RootedHolder();
this.overlapped.AsyncResult = this.rootedHolder;
}
示例10: RegisterWaitForSingleObject
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce)
{
if (executeOnlyOnce != true)
{
throw new NotSupportedException("executeOnlyOnce must be true");
}
int tickTime = (int)Math.Min(100, millisecondsTimeOutInterval);
int totalTimeElapsed = 0;
Timer timer = null;
timer = new Timer((s) =>
{
// Timer will fire every due period...if total time exceeds millisecondsTimeoutInterval then we call the timeoutcallback
// otherwise we wait...if at any point the waitObject is signaled...than we can abort.
if (waitObject.WaitOne(0))
{
// Signal is set so no timeout occured
timer.Dispose();
return;
}
else if (totalTimeElapsed > millisecondsTimeOutInterval)
{
// Timeout has occured
timer.Dispose();
callBack(state, true);
}
else
{
totalTimeElapsed += tickTime;
}
}, null, tickTime, tickTime);
return null;
}
示例11:
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject
(WaitHandle waitObject, WaitOrTimerCallback callBack,
Object state, TimeSpan timeout,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject
(waitObject, callBack, state,
Monitor.TimeSpanToMS(timeout), executeOnlyOnce);
}
示例12: AddMyObjectChanged
internal static void AddMyObjectChanged(EventHandler<ObjectChangedEventArgs> callback,
ref EventHandler<ObjectChangedEventArgs> objectChanged,
object lockObjChangedEvent,
ref RegisteredWaitHandle regObjChangedWaitHandle,
ref AutoResetEvent objChangedEvent,
ref SafeCollabEvent safeObjChangedEvent,
WaitOrTimerCallback ObjectChangedCallback)
{
//
// Register a wait handle if one has not been registered already
//
lock (lockObjChangedEvent){
if (objectChanged == null){
objChangedEvent = new AutoResetEvent(false);
//
// Register callback with a wait handle
//
regObjChangedWaitHandle = ThreadPool.RegisterWaitForSingleObject(objChangedEvent, //Event that triggers the callback
ObjectChangedCallback, //callback to be called
null, //state to be passed
-1, //Timeout - aplicable only for timers
false //call us everytime the event is set
);
PEER_COLLAB_EVENT_REGISTRATION pcer = new PEER_COLLAB_EVENT_REGISTRATION();
pcer.eventType = PeerCollabEventType.MyObjectChanged;
pcer.pInstance = IntPtr.Zero;
//
// Register event with collab
//
int errorCode = UnsafeCollabNativeMethods.PeerCollabRegisterEvent(
objChangedEvent.SafeWaitHandle,
1,
ref pcer,
out safeObjChangedEvent);
if (errorCode != 0){
Logging.P2PTraceSource.TraceEvent(TraceEventType.Error, 0, "PeerCollabRegisterEvent returned with errorcode {0}", errorCode);
throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Collab_ObjectChangedRegFailed), errorCode);
}
}
objectChanged += callback;
}
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "AddObjectChanged() successful.");
}
示例13: UnsafeRegisterWaitForSingleObject
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
throw new NotImplementedException ();
}
示例14: RegisterWaitForSingleObject
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
uint millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) millisecondsTimeOutInterval, executeOnlyOnce);
}
示例15: StartExitCallbackIfNeeded
void StartExitCallbackIfNeeded ()
{
lock (thisLock) {
bool start = (exitWaitHandle == null && enableRaisingEvents && exited_event != null);
if (start && process_handle != IntPtr.Zero) {
WaitOrTimerCallback cb = new WaitOrTimerCallback (CBOnExit);
ProcessWaitHandle h = new ProcessWaitHandle (process_handle);
exitWaitHandle = ThreadPool.RegisterWaitForSingleObject (h, cb, this, -1, true);
}
}
}