protected virtual SuspendedResourcesHolder Suspend(object transaction)
        {
            if (TransactionSynchronizationManager.IsSynchronizationActive())
            {
                var suspendedSynchronizations = DoSuspendSynchronization();
                try
                {
                    object suspendedResources = null;
                    if (transaction != null)
                    {
                        suspendedResources = DoSuspend(transaction);
                    }

                    var name = TransactionSynchronizationManager.GetCurrentTransactionName();
                    TransactionSynchronizationManager.SetCurrentTransactionName(null);
                    var readOnly = TransactionSynchronizationManager.IsCurrentTransactionReadOnly();
                    TransactionSynchronizationManager.SetCurrentTransactionReadOnly(false);
                    var isolationLevel = TransactionSynchronizationManager.GetCurrentTransactionIsolationLevel();
                    TransactionSynchronizationManager.SetCurrentTransactionIsolationLevel(null);
                    var wasActive = TransactionSynchronizationManager.IsActualTransactionActive();
                    TransactionSynchronizationManager.SetActualTransactionActive(false);
                    return(new SuspendedResourcesHolder(suspendedResources, suspendedSynchronizations, name, readOnly, isolationLevel, wasActive));
                }
                catch (Exception)
                {
                    // doSuspend failed - original transaction is still active...
                    DoResumeSynchronization(suspendedSynchronizations);
                    throw;
                }
            }
            else if (transaction != null)
            {
                // Transaction active but no synchronization active.
                var suspendedResources = DoSuspend(transaction);
                return(new SuspendedResourcesHolder(suspendedResources));
            }
            else
            {
                // Neither transaction nor synchronization active.
                return(null);
            }
        }