internal static void FilterExceptionThroughCausalities(ITask task, Exception exception) { try { CausalityThreadContext currentThreadCausalities = Dispatcher.GetCurrentThreadCausalities(); if (CausalityThreadContext.IsEmpty(currentThreadCausalities)) { if (task != null) { DispatcherQueue taskQueue = task.TaskQueue; if (!taskQueue.RaiseUnhandledException(exception)) { Dispatcher dispatcher = taskQueue.Dispatcher; if (dispatcher != null) { dispatcher.RaiseUnhandledException(exception); } } } } else { currentThreadCausalities.PostException(exception); } } catch (Exception exception2) { Dispatcher.LogError(Resource1.ExceptionDuringCausalityHandling, exception2); } }
private void SignalTimer(DispatcherQueue.TimerContext tc) { try { Dispatcher.SetCurrentThreadCausalities(tc.CausalityContext); tc.TimerPort.Post(DateTime.Now); Dispatcher.ClearCausalities(); } catch (Exception exception) { Dispatcher.LogError("DispatcherQueue:TimerHandler", exception); } }
internal void Signal() { if (_cachedWorkerListCount == 0) { Dispatcher.LogError("Dispatcher disposed, will not schedule task", new ObjectDisposedException("Dispatcher")); return; } Interlocked.Increment(ref _pendingTaskCount); for (int i = 0; i < _cachedWorkerListCount; i++) { TaskExecutionWorker taskExecutionWorker = _taskExecutionWorkers[i]; if (taskExecutionWorker.Signal()) { return; } } }
private static void HandleException(ITask currentTask, Exception e) { Dispatcher.LogError(Resource1.HandleExceptionLog, e); Dispatcher.FilterExceptionThroughCausalities(currentTask, e); Dispatcher.SetCurrentThreadCausalities(null); if (currentTask != null && currentTask.ArbiterCleanupHandler != null) { try { currentTask.ArbiterCleanupHandler(); } catch (Exception exception) { Dispatcher.LogError(Resource1.ExceptionDuringArbiterCleanup, exception); } } }
private void ClrSystemTimerHandler(object state) { DispatcherQueue.ClrSystemTimerContext clrSystemTimerContext = (DispatcherQueue.ClrSystemTimerContext)state; try { lock (_clrSystemTimerTable) { _clrSystemTimerTable.Remove(clrSystemTimerContext.Id); } clrSystemTimerContext.Timer.Dispose(); Dispatcher.SetCurrentThreadCausalities(clrSystemTimerContext.CausalityContext); clrSystemTimerContext.TimerPort.Post(DateTime.Now); } catch (Exception exception) { Dispatcher.LogError("DispatcherQueue:TimerHandler", exception); } }
private static void SetWorkerThreadAffinity(DateTime dispatcherStartTime) { try { int num = 0; TimeSpan t = TimeSpan.FromMilliseconds(100.0); foreach (ProcessThread processThread in Process.GetCurrentProcess().Threads) { if (!(processThread.StartTime - dispatcherStartTime > t) && !(processThread.StartTime < dispatcherStartTime) && !(processThread.TotalProcessorTime > t)) { IntPtr processorAffinity = new IntPtr(1 << num++ % Dispatcher.NumberOfProcessorsInternal); processThread.ProcessorAffinity = processorAffinity; } } } catch (Exception exception) { Dispatcher.LogError("Could not set thread affinity", exception); } }