Dispose() public méthode

public Dispose ( ) : void
Résultat void
        public async Task DistributedTransactionFromCompletionEventShouldBeTheOneToWhichTheEventIsAttachedAsync()
        {
            SysTran clone            = null;
            SysTran eventTransaction = null;

            try
            {
                using (CreateDistributedTransactionScope())
                {
                    _log.InfoFormat(
                        "Scope opened, id {0}, distributed id {1}",
                        SysTran.Current.TransactionInformation.LocalIdentifier,
                        SysTran.Current.TransactionInformation.DistributedIdentifier);
                    clone = SysTran.Current.Clone();
                    clone.TransactionCompleted += Clone_TransactionCompleted;
                    _log.Info("Scope not completed");
                }
                _log.Info("Scope disposed");
                while (eventTransaction == null)
                {
                    await(Task.Delay(10));
                }
                _log.Info("Event transaction received");
                Assert.That(eventTransaction, Is.SameAs(clone));
            }
            finally
            {
                clone?.Dispose();
            }

            void Clone_TransactionCompleted(object sender, TransactionEventArgs e)
            {
                eventTransaction = e.Transaction;
            }
        }
        public void DistributedTransactionStatusMustBeInactiveAfterRollbackedScope()
        {
            SysTran transaction = null;

            try
            {
                using (CreateDistributedTransactionScope())
                {
                    _log.InfoFormat(
                        "Scope opened, id {0}, distributed id {1}",
                        SysTran.Current.TransactionInformation.LocalIdentifier,
                        SysTran.Current.TransactionInformation.DistributedIdentifier);
                    // The trouble occurs only with cloned transaction. The original one is disposed before and so
                    // considered inactive by FailsafeGetTransactionStatus test.
                    transaction = SysTran.Current.Clone();
                    _log.Info("Scope not completed");
                }
                _log.Info("Scope disposed");
                Assert.That(FailsafeGetTransactionStatus(transaction), Is.Not.EqualTo(TransactionStatus.Active));
            }
            finally
            {
                transaction?.Dispose();
            }
        }
Exemple #3
0
        public virtual void Dispose()
        {
            _connectionPool              = null;
            _performanceCounters         = null;
            _connectionIsDoomed          = true;
            _enlistedTransactionOriginal = null; // should not be disposed

            // Dispose of the _enlistedTransaction since it is a clone
            // of the original reference.
            // VSDD 780271 - _enlistedTransaction can be changed by another thread (TX end event)
            SysTx.Transaction enlistedTransaction = Interlocked.Exchange(ref _enlistedTransaction, null);
            if (enlistedTransaction != null)
            {
                enlistedTransaction.Dispose();
            }
        }
        public void TransactionStatusMustBeInactiveAfterRollbackedScope()
        {
            SysTran transaction = null;

            try
            {
                using (new TransactionScope())
                {
                    transaction = SysTran.Current.Clone();
                    _log.InfoFormat(
                        "Scope opened, id {0}, distributed id {1}",
                        SysTran.Current.TransactionInformation.LocalIdentifier,
                        SysTran.Current.TransactionInformation.DistributedIdentifier);
                }
                _log.Info("Scope disposed");
                Assert.That(FailsafeGetTransactionStatus(transaction), Is.Not.EqualTo(TransactionStatus.Active));
            }
            finally
            {
                transaction?.Dispose();
            }
        }
        public async Task DistributedTransactionStatusFromCompletionEventShouldNotBeActiveOnRollbackAsync()
        {
            SysTran           clone                   = null;
            SysTran           eventTransaction        = null;
            TransactionStatus?cloneStatusAtCompletion = null;

            try
            {
                using (CreateDistributedTransactionScope())
                {
                    _log.InfoFormat(
                        "Scope opened, id {0}, distributed id {1}",
                        SysTran.Current.TransactionInformation.LocalIdentifier,
                        SysTran.Current.TransactionInformation.DistributedIdentifier);
                    clone = SysTran.Current.Clone();
                    clone.TransactionCompleted += Clone_TransactionCompleted;
                    _log.Info("Scope not completed");
                }
                _log.Info("Scope disposed");
                while (eventTransaction == null)
                {
                    await(Task.Delay(10));
                }
                _log.Info("Event transaction received");
                Assert.That(cloneStatusAtCompletion, Is.Not.EqualTo(TransactionStatus.Active));
            }
            finally
            {
                clone?.Dispose();
            }

            void Clone_TransactionCompleted(object sender, TransactionEventArgs e)
            {
                cloneStatusAtCompletion = FailsafeGetTransactionStatus(clone);
                eventTransaction        = e.Transaction;
            }
        }