TransactionScope Constructors

Definition

Initializes a new instance of the TransactionScope class.

Overloads

TransactionScope()

Initializes a new instance of the TransactionScope class.

TransactionScope(Transaction)

Initializes a new instance of the TransactionScope class and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

TransactionScope(Transaction, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

TransactionScope(TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified asynchronous flow option.

TransactionScope(TransactionScopeOption)

Initializes a new instance of the TransactionScope class with the specified requirements.

TransactionScope(Transaction, TimeSpan, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class with the specified timeout value, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

TransactionScope(TransactionScopeOption, TransactionOptions)

Initializes a new instance of the TransactionScope class with the specified requirements.

TransactionScope(TransactionScopeOption, TransactionOptions, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class with the specified requirements and asynchronous flow option.

TransactionScope(Transaction, TimeSpan)

Initializes a new instance of the TransactionScope class with the specified timeout value, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

TransactionScope(TransactionScopeOption, TimeSpan)

Initializes a new instance of the TransactionScope class with the specified timeout value and requirements.

TransactionScope(TransactionScopeOption, TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified requirements and asynchronous flow option.

TransactionScope(TransactionScopeOption, TransactionOptions, EnterpriseServicesInteropOption)

Initializes a new instance of the TransactionScope class with the specified scope and COM+ interoperability requirements, and transaction options.

TransactionScope(Transaction, TimeSpan, EnterpriseServicesInteropOption)

Initializes a new instance of the TransactionScope class with the specified timeout value and COM+ interoperability requirements, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

TransactionScope(TransactionScopeOption, TimeSpan, TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified timeout value, requirements, and asynchronous flow option.

TransactionScope()

Initializes a new instance of the TransactionScope class.

public:
 TransactionScope();
public TransactionScope ();
Public Sub New ()

Remarks

This constructor creates a new transaction scope with the transaction scope option equal to Required. This means that a transaction is required by the new scope and the ambient transaction is used if one already exists. Otherwise, it creates a new transaction before entering the scope.

See also

TransactionScope(Transaction)

Initializes a new instance of the TransactionScope class and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

public:
 TransactionScope(System::Transactions::Transaction ^ transactionToUse);
public:
 TransactionScope(System::Transactions::Transaction ^ transaction);
public TransactionScope (System.Transactions.Transaction transactionToUse);
public TransactionScope (System.Transactions.Transaction transaction);
new System.Transactions.TransactionScope : System.Transactions.Transaction -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.Transaction -> System.Transactions.TransactionScope
Public Sub New (transactionToUse As Transaction)
Public Sub New (transaction As Transaction)

Parameters

transactionToUsetransaction
Transaction

The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.

See also

TransactionScope(Transaction, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

public:
 TransactionScope(System::Transactions::Transaction ^ transactionToUse, System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.Transaction transactionToUse, System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
new System.Transactions.TransactionScope : System.Transactions.Transaction * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (transactionToUse As Transaction, asyncFlowOption As TransactionScopeAsyncFlowOption)

Parameters

transactionToUse
Transaction

The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.

asyncFlowOption
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

TransactionScope(TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified asynchronous flow option.

public:
 TransactionScope(System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public:
 TransactionScope(System::Transactions::TransactionScopeAsyncFlowOption asyncFlow);
public TransactionScope (System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.TransactionScopeAsyncFlowOption asyncFlow);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (asyncFlowOption As TransactionScopeAsyncFlowOption)
Public Sub New (asyncFlow As TransactionScopeAsyncFlowOption)

Parameters

asyncFlowOptionasyncFlow
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

TransactionScope(TransactionScopeOption)

Initializes a new instance of the TransactionScope class with the specified requirements.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption);
public:
 TransactionScope(System::Transactions::TransactionScopeOption option);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption);
public TransactionScope (System.Transactions.TransactionScopeOption option);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption)
Public Sub New (option As TransactionScopeOption)

Parameters

scopeOptionoption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

See also

TransactionScope(Transaction, TimeSpan, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class with the specified timeout value, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

public:
 TransactionScope(System::Transactions::Transaction ^ transactionToUse, TimeSpan scopeTimeout, System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.Transaction transactionToUse, TimeSpan scopeTimeout, System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
new System.Transactions.TransactionScope : System.Transactions.Transaction * TimeSpan * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (transactionToUse As Transaction, scopeTimeout As TimeSpan, asyncFlowOption As TransactionScopeAsyncFlowOption)

Parameters

transactionToUse
Transaction

The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.

scopeTimeout
TimeSpan

The TimeSpan after which the transaction scope times out and aborts the transaction.

asyncFlowOption
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

TransactionScope(TransactionScopeOption, TransactionOptions)

Initializes a new instance of the TransactionScope class with the specified requirements.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionOptions transactionOptions);
public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionOptions options);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionOptions transactionOptions);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionOptions options);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionOptions -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionOptions -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, transactionOptions As TransactionOptions)
Public Sub New (scopeOption As TransactionScopeOption, options As TransactionOptions)

Parameters

scopeOption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

transactionOptionsoptions
TransactionOptions

A TransactionOptions structure that describes the transaction options to use if a new transaction is created. If an existing transaction is used, the timeout value in this parameter applies to the transaction scope. If that time expires before the scope is disposed, the transaction is aborted.

Remarks

When you use the transactionOptions parameter to specify an IsolationLevel, and the scope creates a transaction later, the new transaction is associated with the specified isolation level. If an isolation level is passed in together with a transaction, the transaction must have an identical isolation level, or an exception is thrown.

See also

TransactionScope(TransactionScopeOption, TransactionOptions, TransactionScopeAsyncFlowOption)

[Supported in the .NET Framework 4.5.1 and later versions]

Initializes a new instance of the TransactionScope class with the specified requirements and asynchronous flow option.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionOptions transactionOptions, System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionOptions transactionOptions, System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionOptions * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, transactionOptions As TransactionOptions, asyncFlowOption As TransactionScopeAsyncFlowOption)

Parameters

scopeOption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

transactionOptions
TransactionOptions

A TransactionOptions structure that describes the transaction options to use if a new transaction is created. If an existing transaction is used, the timeout value in this parameter applies to the transaction scope. If that time expires before the scope is disposed, the transaction is aborted.

asyncFlowOption
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

TransactionScope(Transaction, TimeSpan)

Initializes a new instance of the TransactionScope class with the specified timeout value, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

public:
 TransactionScope(System::Transactions::Transaction ^ transactionToUse, TimeSpan scopeTimeout);
public:
 TransactionScope(System::Transactions::Transaction ^ transaction, TimeSpan timeout);
public TransactionScope (System.Transactions.Transaction transactionToUse, TimeSpan scopeTimeout);
public TransactionScope (System.Transactions.Transaction transaction, TimeSpan timeout);
new System.Transactions.TransactionScope : System.Transactions.Transaction * TimeSpan -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.Transaction * TimeSpan -> System.Transactions.TransactionScope
Public Sub New (transactionToUse As Transaction, scopeTimeout As TimeSpan)
Public Sub New (transaction As Transaction, timeout As TimeSpan)

Parameters

transactionToUsetransaction
Transaction

The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.

scopeTimeouttimeout
TimeSpan

The TimeSpan after which the transaction scope times out and aborts the transaction.

See also

TransactionScope(TransactionScopeOption, TimeSpan)

Initializes a new instance of the TransactionScope class with the specified timeout value and requirements.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, TimeSpan scopeTimeout);
public:
 TransactionScope(System::Transactions::TransactionScopeOption option, TimeSpan timeout);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, TimeSpan scopeTimeout);
public TransactionScope (System.Transactions.TransactionScopeOption option, TimeSpan timeout);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * TimeSpan -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * TimeSpan -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, scopeTimeout As TimeSpan)
Public Sub New (option As TransactionScopeOption, timeout As TimeSpan)

Parameters

scopeOptionoption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

scopeTimeouttimeout
TimeSpan

The TimeSpan after which the transaction scope times out and aborts the transaction.

See also

TransactionScope(TransactionScopeOption, TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified requirements and asynchronous flow option.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public:
 TransactionScope(System::Transactions::TransactionScopeOption option, System::Transactions::TransactionScopeAsyncFlowOption asyncFlow);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.TransactionScopeOption option, System.Transactions.TransactionScopeAsyncFlowOption asyncFlow);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, asyncFlowOption As TransactionScopeAsyncFlowOption)
Public Sub New (option As TransactionScopeOption, asyncFlow As TransactionScopeAsyncFlowOption)

Parameters

scopeOptionoption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

asyncFlowOptionasyncFlow
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

TransactionScope(TransactionScopeOption, TransactionOptions, EnterpriseServicesInteropOption)

Initializes a new instance of the TransactionScope class with the specified scope and COM+ interoperability requirements, and transaction options.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionOptions transactionOptions, System::Transactions::EnterpriseServicesInteropOption interopOption);
public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, System::Transactions::TransactionOptions options, System::Transactions::EnterpriseServicesInteropOption opt);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionOptions transactionOptions, System.Transactions.EnterpriseServicesInteropOption interopOption);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, System.Transactions.TransactionOptions options, System.Transactions.EnterpriseServicesInteropOption opt);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionOptions * System.Transactions.EnterpriseServicesInteropOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * System.Transactions.TransactionOptions * System.Transactions.EnterpriseServicesInteropOption -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, transactionOptions As TransactionOptions, interopOption As EnterpriseServicesInteropOption)
Public Sub New (scopeOption As TransactionScopeOption, options As TransactionOptions, opt As EnterpriseServicesInteropOption)

Parameters

scopeOption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

transactionOptionsoptions
TransactionOptions

A TransactionOptions structure that describes the transaction options to use if a new transaction is created. If an existing transaction is used, the timeout value in this parameter applies to the transaction scope. If that time expires before the scope is disposed, the transaction is aborted.

interopOptionopt
EnterpriseServicesInteropOption

An instance of the EnterpriseServicesInteropOption enumeration that describes how the associated transaction interacts with COM+ transactions.

Remarks

When you use the transactionOptions parameter to specify an IsolationLevel, and the scope creates a transaction later, the new transaction is associated with the specified isolation level. If an isolation level is passed in together with a transaction, the transaction must have an identical isolation level, or an exception is thrown.

Note This method uses LinkDemand to prevent it from being called from untrusted code; however, only the immediate caller is required to possess the FullTrust permission set.

See also

TransactionScope(Transaction, TimeSpan, EnterpriseServicesInteropOption)

Initializes a new instance of the TransactionScope class with the specified timeout value and COM+ interoperability requirements, and sets the specified transaction as the ambient transaction, so that transactional work done inside the scope uses this transaction.

public:
 TransactionScope(System::Transactions::Transaction ^ transactionToUse, TimeSpan scopeTimeout, System::Transactions::EnterpriseServicesInteropOption interopOption);
public:
 TransactionScope(System::Transactions::Transaction ^ transaction, TimeSpan timeout, System::Transactions::EnterpriseServicesInteropOption opt);
public TransactionScope (System.Transactions.Transaction transactionToUse, TimeSpan scopeTimeout, System.Transactions.EnterpriseServicesInteropOption interopOption);
public TransactionScope (System.Transactions.Transaction transaction, TimeSpan timeout, System.Transactions.EnterpriseServicesInteropOption opt);
new System.Transactions.TransactionScope : System.Transactions.Transaction * TimeSpan * System.Transactions.EnterpriseServicesInteropOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.Transaction * TimeSpan * System.Transactions.EnterpriseServicesInteropOption -> System.Transactions.TransactionScope
Public Sub New (transactionToUse As Transaction, scopeTimeout As TimeSpan, interopOption As EnterpriseServicesInteropOption)
Public Sub New (transaction As Transaction, timeout As TimeSpan, opt As EnterpriseServicesInteropOption)

Parameters

transactionToUsetransaction
Transaction

The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.

scopeTimeouttimeout
TimeSpan

The TimeSpan after which the transaction scope times out and aborts the transaction.

interopOptionopt
EnterpriseServicesInteropOption

An instance of the EnterpriseServicesInteropOption enumeration that describes how the associated transaction interacts with COM+ transactions.

Remarks

Note This method uses LinkDemand to prevent it from being called from untrusted code; however, only the immediate caller is required to possess the FullTrust permission set.

See also

TransactionScope(TransactionScopeOption, TimeSpan, TransactionScopeAsyncFlowOption)

Initializes a new instance of the TransactionScope class with the specified timeout value, requirements, and asynchronous flow option.

public:
 TransactionScope(System::Transactions::TransactionScopeOption scopeOption, TimeSpan scopeTimeout, System::Transactions::TransactionScopeAsyncFlowOption asyncFlowOption);
public:
 TransactionScope(System::Transactions::TransactionScopeOption option, TimeSpan timeout, System::Transactions::TransactionScopeAsyncFlowOption asyncFlow);
public TransactionScope (System.Transactions.TransactionScopeOption scopeOption, TimeSpan scopeTimeout, System.Transactions.TransactionScopeAsyncFlowOption asyncFlowOption);
public TransactionScope (System.Transactions.TransactionScopeOption option, TimeSpan timeout, System.Transactions.TransactionScopeAsyncFlowOption asyncFlow);
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * TimeSpan * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
new System.Transactions.TransactionScope : System.Transactions.TransactionScopeOption * TimeSpan * System.Transactions.TransactionScopeAsyncFlowOption -> System.Transactions.TransactionScope
Public Sub New (scopeOption As TransactionScopeOption, scopeTimeout As TimeSpan, asyncFlowOption As TransactionScopeAsyncFlowOption)
Public Sub New (option As TransactionScopeOption, timeout As TimeSpan, asyncFlow As TransactionScopeAsyncFlowOption)

Parameters

scopeOptionoption
TransactionScopeOption

An instance of the TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.

scopeTimeouttimeout
TimeSpan

The TimeSpan after which the transaction scope times out and aborts the transaction.

asyncFlowOptionasyncFlow
TransactionScopeAsyncFlowOption

An instance of the TransactionScopeAsyncFlowOption enumeration that describes whether the ambient transaction associated with the transaction scope will flow across thread continuations when using Task or async/await .NET async programming patterns.

Applies to