System.Transactions.Transaction.GetPromotedToken C# (CSharp) Method

GetPromotedToken() public method

Gets the PromotedToken for the transaction. If the transaction has not already been promoted, retrieving this value will cause promotion. Before retrieving the PromotedToken, the Transaction.PromoterType value should be checked to see if it is a promoter type (Guid) that the caller understands. If the caller does not recognize the PromoterType value, retreiving the PromotedToken doesn't have much value because the caller doesn't know how to utilize it. But if the PromoterType is recognized, the caller should know how to utilize the PromotedToken to communicate with the promoting distributed transaction coordinator to enlist on the distributed transaction. If the value of a transaction's PromoterType is TransactionInterop.PromoterTypeDtc, then that transaction's PromotedToken will be an MSDTC-based TransmitterPropagationToken.
public GetPromotedToken ( ) : byte[]
return byte[]
        public byte[] GetPromotedToken()
        {
            // We need to ask the current transaction state for the PromotedToken because depending on the state
            // we may need to induce a promotion.
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceLtm, this);
            }

            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(Transaction));
            }

            // We always make a copy of the promotedToken stored in the internal transaction.
            byte[] internalPromotedToken;
            lock (_internalTransaction)
            {
                internalPromotedToken = _internalTransaction.State.PromotedToken(_internalTransaction);
            }

            byte[] toReturn = new byte[internalPromotedToken.Length];
            Array.Copy(internalPromotedToken, toReturn, toReturn.Length);
            return toReturn;
        }