Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Dispatch()

static bool System.Threading.ThreadPoolWorkQueue.Dispatch ( )
inlinestaticpackage

Definition at line 489 of file ThreadPoolWorkQueue.cs.

490 {
491 ThreadPoolWorkQueue s_workQueue = ThreadPool.s_workQueue;
492 s_workQueue.MarkThreadRequestSatisfied();
493 s_workQueue.RefreshLoggingEnabled();
494 bool flag = true;
495 try
496 {
497 ThreadPoolWorkQueue threadPoolWorkQueue = s_workQueue;
498 ThreadPoolWorkQueueThreadLocals orCreateThreadLocals = threadPoolWorkQueue.GetOrCreateThreadLocals();
499 object threadLocalCompletionCountObject = orCreateThreadLocals.threadLocalCompletionCountObject;
500 Thread currentThread = orCreateThreadLocals.currentThread;
501 currentThread._executionContext = null;
502 currentThread._synchronizationContext = null;
503 int num = Environment.TickCount;
504 object obj = null;
505 while (true)
506 {
507 if (obj == null)
508 {
509 bool missedSteal = false;
510 obj = threadPoolWorkQueue.Dequeue(orCreateThreadLocals, ref missedSteal);
511 if (obj == null)
512 {
513 flag = missedSteal;
514 return true;
515 }
516 }
517 if (threadPoolWorkQueue.loggingEnabled && FrameworkEventSource.Log.IsEnabled())
518 {
519 FrameworkEventSource.Log.ThreadPoolDequeueWorkObject(obj);
520 }
521 threadPoolWorkQueue.EnsureThreadRequested();
522 if (ThreadPool.EnableWorkerTracking)
523 {
525 }
526 else
527 {
528 DispatchWorkItem(obj, currentThread);
529 }
530 obj = null;
531 ExecutionContext.ResetThreadPoolThread(currentThread);
532 currentThread.ResetThreadPoolThread();
533 int tickCount = Environment.TickCount;
534 if (!ThreadPool.NotifyWorkItemComplete(threadLocalCompletionCountObject, tickCount))
535 {
536 orCreateThreadLocals.TransferLocalWork();
537 return false;
538 }
539 if ((uint)(tickCount - num) >= 30u)
540 {
541 if (!ThreadPool.SupportsTimeSensitiveWorkItems)
542 {
543 break;
544 }
545 num = tickCount;
546 threadPoolWorkQueue.RefreshLoggingEnabled();
547 obj = threadPoolWorkQueue.TryDequeueTimeSensitiveWorkItem();
548 }
549 }
550 return true;
551 }
552 finally
553 {
554 if (flag)
555 {
556 s_workQueue.EnsureThreadRequested();
557 }
558 }
559 }
static void DispatchWorkItem(object workItem, Thread currentThread)
static void DispatchWorkItemWithWorkerTracking(object workItem, Thread currentThread)

References System.Threading.ThreadPoolWorkQueueThreadLocals.currentThread, System.Threading.ThreadPoolWorkQueue.Dequeue(), System.Threading.ThreadPoolWorkQueue.DispatchWorkItem(), System.Threading.ThreadPoolWorkQueue.DispatchWorkItemWithWorkerTracking(), System.Threading.ThreadPool.EnableWorkerTracking, System.Threading.ThreadPoolWorkQueue.EnsureThreadRequested(), System.Threading.ThreadPoolWorkQueue.GetOrCreateThreadLocals(), System.Diagnostics.Tracing.FrameworkEventSource.Log, System.Threading.ThreadPoolWorkQueue.loggingEnabled, System.Threading.ThreadPoolWorkQueue.MarkThreadRequestSatisfied(), System.Threading.ThreadPool.NotifyWorkItemComplete(), System.obj, System.Threading.ThreadPoolWorkQueue.RefreshLoggingEnabled(), System.Threading.Thread.ResetThreadPoolThread(), System.Threading.ExecutionContext.ResetThreadPoolThread(), System.Threading.ThreadPool.s_workQueue, System.Threading.ThreadPool.SupportsTimeSensitiveWorkItems, System.Threading.ThreadPoolWorkQueueThreadLocals.threadLocalCompletionCountObject, System.Environment.TickCount, System.Threading.ThreadPoolWorkQueueThreadLocals.TransferLocalWork(), and System.Threading.ThreadPoolWorkQueue.TryDequeueTimeSensitiveWorkItem().

Referenced by System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(), and System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart().