コード例 #1
0
        // private methods
        private void RunMaintenance(MaintenanceExecutingContext maintenanceExecutingContext)
        {
            try
            {
                var cancellationToken = maintenanceExecutingContext.CancellationToken;

                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        _connectionPool.ConnectionHolder.Prune(maxExpiredGenerationInUse: null, cancellationToken);
                        EnsureMinSize(cancellationToken);
                    }
                    catch
                    {
                    }

                    maintenanceExecutingContext.Wait();
                }

                _connectionPool.ConnectionHolder.Prune(maintenanceExecutingContext.MaxGenerationToReap, _globalCancellationToken);
            }
            catch
            {
                // ignore exceptions
            }
        }
コード例 #2
0
        public void Start()
        {
            if (_interval == Timeout.InfiniteTimeSpan || IsRunning)
            {
                return;
            }

            _maintenanceExecutingContext = new MaintenanceExecutingContext(_interval, _globalCancellationToken);

            _maintenanceThread = new Thread(new ParameterizedThreadStart(ThreadStart))
            {
                IsBackground = true
            };
            _maintenanceThread.Start(_maintenanceExecutingContext);

            void ThreadStart(object maintenanceExecutingContextObj)
            {
                var maintenanceExecutingContext = (MaintenanceExecutingContext)maintenanceExecutingContextObj;

                RunMaintenance(maintenanceExecutingContext);
            }
        }