public bool Enqueue(T item) { var r = false; var reThrowException = false; var enabledCountPerformance = true; if (_onEnabledCountPerformanceProcessFunc != null) { enabledCountPerformance = _onEnabledCountPerformanceProcessFunc(); } var qpcc = PerformanceCountersContainer; PerformanceCountersHelper .TryCountPerformance ( () => { return(enabledCountPerformance); } , reThrowException , qpcc .IncrementCountersBeforeCountPerformanceForEnqueue //incrementCountersBeforeCountPerformance , null , null , () => { Stopwatch stopwatchEnqueue = null; if (_isAttachedPerformanceCounters) { stopwatchEnqueue = _stopwatchsPool.Get(); } stopwatchEnqueue.Start(); var element = Tuple .Create ( stopwatchEnqueue , item ); _queue.Enqueue(element); r = true; } , (x, y, z) => { qpcc .CaughtExceptionsPerformanceCounter .Increment(); if (OnEnqueueProcessCaughtException != null) { reThrowException = OnEnqueueProcessCaughtException(this, x, y, z); } if (!reThrowException) { if (OnCaughtException != null) { reThrowException = OnCaughtException(this, x, y, z); } } return(reThrowException); } , (x, y, z, w) => { if ( _waitingDequeueThreadsProcessorsStack != null && _waitingDequeueThreadsProcessorsStack.Count > 0 ) { ThreadProcessor processor = null; if ( _waitingDequeueThreadsProcessorsStack .TryPop(out processor) ) { processor.Waiter.Set(); processor = null; //Console.WriteLine("processor = null; {0}", _waitingDequeueThreadsProcessorsStack.Count); } } } ); return(r); }
public bool Enqueue(T item) { var r = false; var reThrowException = false; var enabledCountPerformance = true; if (OnGetEnabledCountPerformanceProcessFunc != null) { enabledCountPerformance = OnGetEnabledCountPerformanceProcessFunc(); } var qpcc = _queuePerformanceCountersContainer; PerformanceCountersHelper .TryCountPerformance ( () => { return(enabledCountPerformance); } , reThrowException , qpcc .IncrementCountersBeforeCountPerformanceForEnqueue //incrementCountersBeforeCountPerformance , null , null , () => { Stopwatch stopwatchEnqueue = null; if (_isAttachedPerformanceCounters) { stopwatchEnqueue = _stopwatchsPool.Get(); } stopwatchEnqueue.Start(); var element = Tuple .Create ( stopwatchEnqueue , item ); _queue.Enqueue(element); //Thread.Sleep(100); r = true; } , (x, y, z) => { qpcc .CaughtExceptionsPerformanceCounter .Increment(); if (OnEnqueueProcessCaughtException != null) { reThrowException = OnEnqueueProcessCaughtException(this, x, y, z); } if (!reThrowException) { if (OnCaughtException != null) { reThrowException = OnCaughtException(this, x, y, z); } } return(reThrowException); } ); return(r); }
public static Stopwatch CountPerformanceBegin ( MultiPerformanceCountersTypeFlags enabledPerformanceCounters , string performanceCountersCategoryName , string performanceCountersCategoryInstanceName ) { Stopwatch r = null; if (enabledPerformanceCounters != MultiPerformanceCountersTypeFlags.None) { string key = string.Format ( "{1}{0}{2}" , "-" , performanceCountersCategoryName , performanceCountersCategoryInstanceName ); TPerformanceCountersContainer container = null; if (!_dictionary.TryGetValue(key, out container)) { lock (_lockerObject) { container = default(TPerformanceCountersContainer); _dictionary.Add ( key , container ); container.AttachPerformanceCountersToProperties ( performanceCountersCategoryInstanceName , performanceCountersCategoryName ); } } var enableProcessCounter = ( ( enabledPerformanceCounters & MultiPerformanceCountersTypeFlags.ProcessCounter ) != MultiPerformanceCountersTypeFlags.None ); if (enableProcessCounter) { container.PrcocessPerformanceCounter.Increment(); } var enableProcessingCounter = ( ( enabledPerformanceCounters & MultiPerformanceCountersTypeFlags.ProcessingCounter ) != MultiPerformanceCountersTypeFlags.None ); if (enableProcessingCounter) { container.ProcessingPerformanceCounter.Increment(); } var enableProcessedAverageTimerCounter = ( ( enabledPerformanceCounters & MultiPerformanceCountersTypeFlags.ProcessedAverageTimerCounter ) != MultiPerformanceCountersTypeFlags.None ); if (enableProcessedAverageTimerCounter) { r = _stopwatchsPool.Get(); //Stopwatch.StartNew(); r.Reset(); r.Start(); } } return(r); }