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

Rollback() public method

public Rollback ( ) : void
return void
        public void Rollback()
        {
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceLtm, this);
                etwLog.TransactionRollback(this, "Transaction");
            }

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

            lock (_internalTransaction)
            {
                Debug.Assert(_internalTransaction.State != null);
                _internalTransaction.State.Rollback(_internalTransaction, null);
            }

            if (etwLog.IsEnabled())
            {
                etwLog.MethodExit(TraceSourceType.TraceSourceLtm, this);
            }
        }

Same methods

Transaction::Rollback ( Exception e ) : void
Transaction::Rollback ( System e ) : void

Usage Example

Example #1
0
        /// <summary>
        /// Write a file with transaction
        /// </summary>
        /// <param name="data">Data to write</param>
        /// <param name="path">Path to file</param>
        /// <returns>Statut de l'opration</returns>
        public static bool WriteStateFileTransacted(string path, XmlSerializer stateSerializer, AtomState atomState, System.Transactions.Transaction transaction)
        {
            if (atomState == null)
            {
                return(false);
            }

            SafeTransactionHandle txHandle   = null;
            SafeFileHandle        fileHandle = null;
            bool response = true;

            try
            {
                IKernelTransaction kernelTx = (IKernelTransaction)TransactionInterop.GetDtcTransaction(transaction);
                kernelTx.GetHandle(out txHandle);

                fileHandle
                    = CreateFileTransacted(
                          path
                          , SafeTransactionHandle.FileAccess.GENERIC_WRITE
                          , SafeTransactionHandle.FileShare.FILE_SHARE_NONE
                          , IntPtr.Zero
                          , SafeTransactionHandle.FileMode.CREATE_ALWAYS
                          , 0
                          , IntPtr.Zero
                          , txHandle
                          , IntPtr.Zero
                          , IntPtr.Zero);

                if (fileHandle.IsInvalid)
                {
                    throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
                }

                using (FileStream stateFile = new FileStream(fileHandle, FileAccess.Write, 1024, false))
                {
                    stateSerializer.Serialize(stateFile, atomState);
                }
            }
            catch
            {
                transaction.Rollback();
                response = false;
            }
            finally
            {
                if (fileHandle != null && !fileHandle.IsInvalid)
                {
                    fileHandle.Close();
                    fileHandle.Dispose();
                }

                if (txHandle != null && !txHandle.IsInvalid)
                {
                    txHandle.Close();
                    txHandle.Dispose();
                }
            }
            return(response);
        }
All Usage Examples Of System.Transactions.Transaction::Rollback