Exemplo n.º 1
0
        void RunMonitor()
        {
            var lists = new Lists(Lists.LogPerformanceLists);
            var listsWithChangedProperties = new Lists(Lists.LogPerformanceListsWithChangedProperties);
            var listsWithItemsToBeRemoved  = new Lists(Lists.LogPerformanceListsWithItemsToBeRemoved);

            var stopwatch = new Stopwatch();

            int monitoredProperties;

            while (!cancellation.IsCancellationRequested)
            {
                stopwatch.Stop();

                EventSource.Log.PerformanceCycleTime(stopwatch.ElapsedMilliseconds);

                if (cancellation.Token.WaitHandle.WaitOne(15))
                {
                    return;
                }

                countEventForSuspensions.WaitForZeroOrCancellation(cancellation.Token);
                if (cancellation.IsCancellationRequested)
                {
                    return;
                }

                stopwatch.Restart();

                lists.Clear();
                listsWithItemsToBeRemoved.Clear();
                listsWithChangedProperties.Clear();

                lock (observableObjectTable)
                {
                    lists.Add(observableObjectInfos);
                }

                lists.LogPerformance();

                if (lists.AreEmpty)
                {
                    listsWithChangedProperties.LogPerformance();
                    listsWithItemsToBeRemoved.LogPerformance();

                    continue;
                }

                // updating values (retrieving current values)
                try
                {
                    lists.UpdateValues(NotificationContext, listsWithItemsToBeRemoved);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    EventSource.Log.StoppingDueToFailedUpdate(e.ToString());

                    throw;
                }

                // analyzing values
                monitoredProperties = lists.AnalyzeValues();

                // sending change notifications
                listsWithChangedProperties.AddWithChangedProperties(lists);

                listsWithChangedProperties.LogPerformance();

                try
                {
                    listsWithChangedProperties.SendNotifications(NotificationContext, listsWithItemsToBeRemoved);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    EventSource.Log.StoppingDueToFailedChangeNotifications(e.ToString());

                    throw;
                }

                EventSource.Log.PerformanceMonitoredProperties(monitoredProperties);

                // clearing
                listsWithItemsToBeRemoved.LogPerformance();

                if (listsWithItemsToBeRemoved.AreEmpty)
                {
                    continue;
                }

                lock (observableObjectTable)
                {
                    listsWithItemsToBeRemoved.ClearSets(observableObjectInfos);
                }
            }
        }