当前位置: 首页>>代码示例>>C#>>正文


C# InternalTransaction.SetPromoterTypeToMSDTC方法代码示例

本文整理汇总了C#中System.Transactions.InternalTransaction.SetPromoterTypeToMSDTC方法的典型用法代码示例。如果您正苦于以下问题:C# InternalTransaction.SetPromoterTypeToMSDTC方法的具体用法?C# InternalTransaction.SetPromoterTypeToMSDTC怎么用?C# InternalTransaction.SetPromoterTypeToMSDTC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Transactions.InternalTransaction的用法示例。


在下文中一共展示了InternalTransaction.SetPromoterTypeToMSDTC方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnterState

        internal override void EnterState(InternalTransaction tx)
        {
            Debug.Assert((tx._promoterType == Guid.Empty) || (tx._promoterType == TransactionInterop.PromoterTypeDtc), "Promoted to MSTC but PromoterType is not TransactionInterop.PromoterTypeDtc");
            // The promoterType may not yet be set. This state assumes we are promoting to MSDTC.
            tx.SetPromoterTypeToMSDTC();

            if (tx._outcomeSource._isoLevel == IsolationLevel.Snapshot)
            {
                throw TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceLtm,
                    SR.CannotPromoteSnapshot, null);
            }

            // Set the transaction state
            CommonEnterState(tx);

            // Create a transaction with the distributed transaction manager
            DistributedCommittableTransaction distributedTx = null;
            try
            {
                TimeSpan newTimeout;
                if (tx.AbsoluteTimeout == long.MaxValue)
                {
                    // The transaction has no timeout
                    newTimeout = TimeSpan.Zero;
                }
                else
                {
                    newTimeout = TransactionManager.TransactionTable.RecalcTimeout(tx);
                    if (newTimeout <= TimeSpan.Zero)
                    {
                        return;
                    }
                }

                // Just create a new transaction.
                TransactionOptions options = new TransactionOptions();

                options.IsolationLevel = tx._outcomeSource._isoLevel;
                options.Timeout = newTimeout;

                // Create a new distributed transaction.
                distributedTx =
                    TransactionManager.DistributedTransactionManager.CreateTransaction(options);
                distributedTx.SavedLtmPromotedTransaction = tx._outcomeSource;

                TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
                if (etwLog.IsEnabled())
                {
                    etwLog.TransactionPromoted(tx.TransactionTraceId, distributedTx.TransactionTraceId);
                }
            }
            catch (TransactionException te)
            {
                // There was an exception trying to create the distributed transaction.
                // Save the exception and let the transaction get aborted by the finally block.
                tx._innerException = te;
                TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
                if (etwLog.IsEnabled())
                {
                    etwLog.ExceptionConsumed(te);
                }
                return;
            }
            finally
            {
                if (distributedTx == null)
                {
                    // There was an exception trying to create the distributed transaction abort
                    // the local transaction and exit.
                    tx.State.ChangeStateAbortedDuringPromotion(tx);
                }
            }

            // Associate the distributed transaction with the local transaction.
            tx.PromotedTransaction = distributedTx;

            // Add a weak reference to the transaction to the promotedTransactionTable.
            Hashtable promotedTransactionTable = TransactionManager.PromotedTransactionTable;
            lock (promotedTransactionTable)
            {
                // Since we are adding this reference to the table create an object that will clean that
                // entry up.
                tx._finalizedObject = new FinalizedObject(tx, distributedTx.Identifier);

                WeakReference weakRef = new WeakReference(tx._outcomeSource, false);
                promotedTransactionTable[distributedTx.Identifier] = weakRef;
            }
            TransactionManager.FireDistributedTransactionStarted(tx._outcomeSource);

            // Once we have a promoted transaction promote the enlistments.
            PromoteEnlistmentsAndOutcome(tx);
        }
开发者ID:hughbe,项目名称:corefx,代码行数:92,代码来源:TransactionState.cs

示例2: Transaction

        internal Transaction(IsolationLevel isoLevel, ISimpleTransactionSuperior superior)
        {
            TransactionManager.ValidateIsolationLevel(isoLevel);

            if (superior == null)
            {
                throw new ArgumentNullException(nameof(superior));
            }

            _isoLevel = isoLevel;

            // Never create a transaction with an IsolationLevel of Unspecified.
            if (IsolationLevel.Unspecified == _isoLevel)
            {
                _isoLevel = TransactionManager.DefaultIsolationLevel;
            }

            _internalTransaction = new InternalTransaction(this, superior);
            // ISimpleTransactionSuperior is defined to also promote to MSDTC.
            _internalTransaction.SetPromoterTypeToMSDTC();
            _cloneId = 1;
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:22,代码来源:Transaction.cs


注:本文中的System.Transactions.InternalTransaction.SetPromoterTypeToMSDTC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。