Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.MetricsEventManager.TimerFlush C# (CSharp) Method

TimerFlush() protected method

Flush any queued events to event source immediately.
This method may run concurrently with itself so ensure there are no unintended side effects or race conditions within the implementation.
protected TimerFlush ( object state ) : void
state object
return void
        protected internal virtual void TimerFlush(object state)
        {
            if (QueuedEvents.Count == 0)
            {
                return;
            }

            SystemMetricEvent[] eventsToFlush = QueuedEvents.Values.ToArray();
            QueuedEvents.Clear();

            // Use the same timestamp for all events. Since these are
            // aggregated events, individual timestamps for when the events were
            // started are meaningless
            DateTime eventTimestamp = DateTime.UtcNow;

            foreach (SystemMetricEvent evt in eventsToFlush)
            {
                evt.Timestamp = eventTimestamp;

                // perform the average calculation that we have postponed
                evt.Average /= evt.Count;
            }

            WriteMetricEvents(eventsToFlush);
        }