Ejemplo n.º 1
0
 public void Dispose()
 {
     if (_sw != null)
     {
         _sw.Stop();
         var newMaximum = _etsc.OnMeasuredExecutionTime(_actionVisibleId, _sw.Elapsed.TotalMilliseconds, Details);
         var wtl        = newMaximum ? _writeToLogNewMaximum : _writeToLog;
         wtl?.Invoke($"stopped tracker {_actionVisibleId}: {_sw.Elapsed.TotalMilliseconds}ms {Details}");
         _sw = null;
     }
 }
Ejemplo n.º 2
0
        void ExecuteDelayedActions()
        {
            // linkedlist example:  100sec   102sec  104sec   108sec
            //       now:              10sec    102sec

            var now = Time;

            foreach (var eventsSortedByDueTime in _delayedActionsSortedByDueTime)
            {
                for (var item = eventsSortedByDueTime.First; ;)
                {
                    if (item == null)
                    {
                        break;
                    }
                    var e = item.Value;
                    if (e.DueTime > now)
                    {
                        break;
                    }

                    // go to next item
                    var itemToRemove = item;
                    item = item.Next;

                    // execute item
                    try
                    {
                        if (_etscNullable != null)
                        {
                            var sw = Stopwatch.StartNew();
                            e.EventHandler();
                            sw.Stop();
                            _etscNullable?.OnMeasuredExecutionTime(e.ActionVisibleId, sw.Elapsed.TotalMilliseconds);
                        }
                        else
                        {
                            e.EventHandler();
                        }
                    }
                    catch (Exception exc)
                    {
                        _onException(exc);
                    }
                    if (_isDisposing)
                    {
                        return;
                    }

                    // remove executed item
                    eventsSortedByDueTime.Remove(itemToRemove);
                }
            }
        }
Ejemplo n.º 3
0
        public void ExecuteQueued()
        {
            var x = Thread.CurrentThread.ManagedThreadId;

            for (; ;)
            {
                QueuedAction a;
                lock (_queue)
                {
                    a = _queue.Count != 0 ? _queue.Dequeue() : null;
                }
                if (a == null)
                {
                    goto _next;
                }
                if (_isDisposing)
                {
                    return;
                }

                try
                {
                    var sw = Stopwatch.StartNew();
                    a.A();
                    sw.Stop();
                    _etscNullable?.OnMeasuredExecutionTime(a.ActionVisibleId, sw.Elapsed.TotalMilliseconds);
                }
                catch (Exception exc)
                {
                    _onException(exc);
                }
            }

_next:
            ExecuteDelayedActions();
        }