Esempio n. 1
0
        static void Main()
        {
            ParseCommandLineArguments();
            SetIntervalAndRepetitions();

            _nativeTarget = new NativeTarget(_options.PidsToFilter.First());
            _session      = new LiveSession();

            Console.CancelKeyPress += (sender, args) =>
            {
                Console.Error.WriteLine("Ctrl+C pressed, stopping...");
                args.Cancel = true;
                _session?.Dispose();
                _nativeTarget?.Dispose();
                _timer?.Dispose();
            };

            SetupTimer();
            _session.Start(_options.PidsToFilter.First());

            if (_interval == TimeSpan.Zero)
            {
                OnTimer();
            }

            Console.ReadLine();
        }
Esempio n. 2
0
        private static void SetupTimer()
        {
            // If there is no interval, we don't need to print at timed intervals. Just wait for the
            // user to hit Ctrl+C and exit the session.
            if (_interval == TimeSpan.Zero)
            {
                return;
            }

            object timerSyncObject = new object();

            _timer = new Timer(_ =>
            {
                // Prevent multiple invocations of the timer from running concurrently,
                // and if not enough time has elapsed, don't run the timer procedure again.
                // This may happen if there are a lot of symbols to resolve, and the timer
                // can't keep up (at least at first).
                lock (timerSyncObject)
                {
                    if (DateTime.Now - _lastTimerInvocation < _interval)
                    {
                        return;
                    }

                    _lastTimerInvocation = DateTime.Now;
                    OnTimer();
                    if (--_invocationsLeft == 0)
                    {
                        _session.Dispose();
                        _nativeTarget.Dispose();
                        _timer.Dispose();
                        _session      = null;
                        _nativeTarget = null;
                        _timer        = null;
                    }
                }
            }, null, _interval, _interval);
        }