Beispiel #1
0
        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            BerkeleyDbStorage errorStorage = null;
            BdbException      bdbExc       = null;
            Exception         regExc       = null;
            var errorHandleIteration       = -1;

            lock (disposeLock)
            {
                if (timer == null)
                {
                    return;                                // for race condition where Elapsed event fires even after Dispose called
                }
                timer.Stop();
                if (storage == null)
                {
                    return;
                }
                if (storage.IsShuttingDown)
                {
                    return;
                }
                if (storage.IsInRecovery)
                {
                    return;
                }
                try
                {
                    storage.BlockOnRecovery();
                    callback();
                }
                catch (BdbException exc)
                {
                    errorStorage         = storage;
                    errorHandleIteration = errorStorage.HandleIteration;
                    bdbExc = exc;
                }
                catch (Exception exc)
                {
                    errorStorage         = storage;
                    errorHandleIteration = errorStorage.HandleIteration;
                    regExc = exc;
                }
            }
            // needed to store storage in case Dispose called after lock, but need to do error handling outside of lock
            // because error handler might wind up calling Dispose, which also uses lock
            if (errorStorage != null && errorHandleIteration == errorStorage.HandleIteration)
            {
                if (bdbExc != null)
                {
                    errorStorage.HandleBdbError(bdbExc);
                }
                else
                {
                    errorStorage.HandleGeneralError(regExc);
                }
            }
            if (timer != null)
            {
                timer.Start();
            }
        }