private void InnerBegin()
        {
            Contract.Ensures(_State == TransactionState.Active);
            // we have a ongoing current transaction, join it!
            if (System.Transactions.Transaction.Current != null)
            {
                var ktx = (IKernelTransaction)TransactionInterop.GetDtcTransaction(System.Transactions.Transaction.Current);

                SafeKernelTransactionHandle handle;
                ktx.GetHandle(out handle);

                // even though _TransactionHandle can already contain a handle if this thread
                // had been yielded just before setting this reference, the "safe"-ness of the wrapper should
                // not dispose the other handle which is now removed
                _TransactionHandle = handle;
                //IsAmbient = true; // TODO: Perhaps we created this item and we need to notify the transaction manager...
            }
            else
            {
                _TransactionHandle = NativeMethods.CreateTransaction(string.Format("{0} Transaction", _Name));
            }

            if (!_TransactionHandle.IsInvalid)
            {
                _State = TransactionState.Active;
                return;
            }

            throw new TransactionException(
                      "Cannot begin file transaction. CreateTransaction failed and there's no ambient transaction.",
                      LastEx());
        }
Example #2
0
		private void InnerBegin()
		{
			Contract.Ensures(_State == TransactionState.Active);
			// we have a ongoing current transaction, join it!
			if (System.Transactions.Transaction.Current != null)
			{
				var ktx = (IKernelTransaction) TransactionInterop.GetDtcTransaction(System.Transactions.Transaction.Current);
				
				SafeKernelTransactionHandle handle;
				ktx.GetHandle(out handle);

				// even though _TransactionHandle can already contain a handle if this thread 
				// had been yielded just before setting this reference, the "safe"-ness of the wrapper should
				// not dispose the other handle which is now removed
				_TransactionHandle = handle;
				//IsAmbient = true; // TODO: Perhaps we created this item and we need to notify the transaction manager...
			}
			else _TransactionHandle = NativeMethods.CreateTransaction(string.Format("{0} Transaction", _Name));

			if (!_TransactionHandle.IsInvalid)
			{
				_State = TransactionState.Active;
				return;
			}

			throw new TransactionException(
				"Cannot begin file transaction. CreateTransaction failed and there's no ambient transaction.",
				LastEx());
		}