DependentTransaction DependentTransaction DependentTransaction DependentTransaction Class

定義

トランザクションの作業に関してアプリケーションが停止するまで、トランザクションをコミットできないようにする、トランザクションの複製を記述します。Describes a clone of a transaction providing guarantee that the transaction cannot be committed until the application comes to rest regarding work on the transaction. このクラスは継承できません。This class cannot be inherited.

public ref class DependentTransaction sealed : System::Transactions::Transaction, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class DependentTransaction : System.Transactions.Transaction, System.Runtime.Serialization.ISerializable
type DependentTransaction = class
    inherit Transaction
    interface ISerializable
Public NotInheritable Class DependentTransaction
Inherits Transaction
Implements ISerializable
継承
DependentTransactionDependentTransactionDependentTransactionDependentTransaction
属性
実装

次の例では、依存トランザクションを作成する方法を示します。The following example shows you how to create a dependent transaction.

static void Main(string[] args)
{
	try
	{
		using (TransactionScope scope = new TransactionScope())
		{
			// Perform transactional work here.

			//Queue work item
			ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerThread), Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete));

			//Display transaction information
			Console.WriteLine("Transaction information:");
			Console.WriteLine("ID:             {0}", Transaction.Current.TransactionInformation.LocalIdentifier);
			Console.WriteLine("status:         {0}", Transaction.Current.TransactionInformation.Status);
			Console.WriteLine("isolationlevel: {0}", Transaction.Current.IsolationLevel);

			//Call Complete on the TransactionScope based on console input
			ConsoleKeyInfo c;
			while (true)
			{
                      			Console.Write("Complete the transaction scope? [Y|N] ");
				c = Console.ReadKey();
				Console.WriteLine();

				if ((c.KeyChar == 'Y') || (c.KeyChar == 'y'))
				{
					//Call complete on the scope
					scope.Complete();
					break;
				}
				else if ((c.KeyChar == 'N') || (c.KeyChar == 'n'))
				{
					break;
				}
			}

		}
	}
	catch (System.Transactions.TransactionException ex)
	{
		Console.WriteLine(ex);
	}
	catch
	{
		Console.WriteLine("Cannot complete transaction");
		throw;
	}
	
}

private static void WorkerThread(object transaction)
{
	//Create a DependentTransaction from the object passed to the WorkerThread
	DependentTransaction dTx = (DependentTransaction)transaction;

	//Sleep for 1 second to force the worker thread to delay
	Thread.Sleep(1000);

	//Pass the DependentTransaction to the scope, so that work done in the scope becomes part of the transaction passed to the worker thread
	using (TransactionScope ts = new TransactionScope(dTx))
	{
		//Perform transactional work here.

		//Call complete on the transaction scope
		ts.Complete();
	}

	//Call complete on the dependent transaction
	dTx.Complete();
}
Public Shared Sub Main()
	Try
		Using scope As TransactionScope = New TransactionScope()

			'Perform transactional work here.

			'Queue work item
			ThreadPool.QueueUserWorkItem(AddressOf WorkerThread, Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete))

			'Display transaction information
			Console.WriteLine("Transaction information:")
			Console.WriteLine("ID:             {0}", Transaction.Current.TransactionInformation.LocalIdentifier)
			Console.WriteLine("status:         {0}", Transaction.Current.TransactionInformation.Status)
			Console.WriteLine("isolationlevel: {0}", Transaction.Current.IsolationLevel)

			'Call Complete on the TransactionScope based on console input
			Dim c As ConsoleKeyInfo
			While (True)

				Console.Write("Complete the transaction scope? [Y|N] ")
				c = Console.ReadKey()
				Console.WriteLine()
				If (c.KeyChar = "Y") Or (c.KeyChar = "y") Then
					scope.Complete()
					Exit While
				ElseIf ((c.KeyChar = "N") Or (c.KeyChar = "n")) Then
					Exit While
				End If
			End While
		End Using

	Catch ex As TransactionException
		Console.WriteLine(ex)
	Catch
		Console.WriteLine("Cannot complete transaction")
		Throw
	End Try
End Sub

Public Shared Sub WorkerThread(ByVal myTransaction As Object)

	'Create a DependentTransaction from the object passed to the WorkerThread
	Dim dTx As DependentTransaction
	dTx = CType(myTransaction, DependentTransaction)

	'Sleep for 1 second to force the worker thread to delay
	Thread.Sleep(1000)

	'Pass the DependentTransaction to the scope, so that work done in the scope becomes part of the transaction passed to the worker thread
	Using ts As TransactionScope = New TransactionScope(dTx)
		'Perform transactional work here.

		'Call complete on the transaction scope
		ts.Complete()
	End Using

	'Call complete on the dependent transaction
	dTx.Complete()
End Sub

注釈

DependentTransactionのクローンである、Transactionオブジェクトを使用して作成、DependentCloneメソッド。The DependentTransaction is a clone of a Transaction object created using the DependentClone method. その唯一の目的では、rest し、(たとえば、ワーカー スレッド) でトランザクションの作業が実行されているときにトランザクションをコミットできないことを保証するアプリケーションを許可します。Its sole purpose is to allow the application to come to rest and guarantee that the transaction cannot commit while work is still being performed on the transaction (for example, on a worker thread).

使用して、トランザクションの作成者を通知できます複製されたトランザクション内で行われる作業は完了してコミットする準備では最後に、ときに、Completeメソッド。When the work done within the cloned transaction is finally complete and ready to be committed, it can inform the creator of the transaction using the Complete method. そのため、整合性とデータの正確性を保持できます。Thus you can preserve the consistency and correctness of data.

DependentCloneOptionコミット時に動作を決定する列挙を使用します。The DependentCloneOption enumeration is used to determine the behavior on commit. この動作の制御ではアプリケーションを停止も同時実行のサポートを提供します。This behavior control allows an application to come to rest, as well as provides concurrency support. この列挙体を使用する方法の詳細については、次を参照してください。 DependentTransaction による同時実行を管理するします。For more information on how this enumeration is used, see Managing Concurrency with DependentTransaction.

メソッド

BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) Inherited from Transaction
Clone() Clone() Clone() Clone()

トランザクションの複製を作成します。Creates a clone of the transaction.

(Inherited from Transaction)
Complete() Complete() Complete() Complete()

依存トランザクションの完了を試みます。Attempts to complete the dependent transaction.

DependentClone(DependentCloneOption) DependentClone(DependentCloneOption) DependentClone(DependentCloneOption) DependentClone(DependentCloneOption)

トランザクションの依存する複製を作成します。Creates a dependent clone of the transaction.

(Inherited from Transaction)
Dispose() Dispose() Dispose() Dispose()

オブジェクトによって保持されているリソースを解放します。Releases the resources that are held by the object.

(Inherited from Transaction)
EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) Inherited from Transaction
EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions)

トランザクションに参加する 2 フェーズ コミットをサポートする永続的リソース マネージャーを参加させます。Enlists a durable resource manager that supports two phase commit to participate in a transaction.

(Inherited from Transaction)
EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions)

トランザクションで参加する単一フェーズ コミットの最適化をサポートする永続的リソース マネージャーを参加させます。Enlists a durable resource manager that supports single phase commit optimization to participate in a transaction.

(Inherited from Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification)

昇格可能な単一フェーズの参加リスト (PSPE) を使用して、内部トランザクションを持つリソース マネージャーを参加させます。Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(Inherited from Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid)

昇格可能な単一フェーズの参加リスト (PSPE) を使用して、内部トランザクションを持つリソース マネージャーを参加させます。Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(Inherited from Transaction)
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

トランザクションに参加する 2 フェーズ コミットをサポートしている揮発性リソース マネージャーを参加させます。Enlists a volatile resource manager that supports two phase commit to participate in a transaction.

(Inherited from Transaction)
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

トランザクションで単一フェーズ コミットの最適化をサポートしている揮発性リソース マネージャーを参加させます。Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction.

(Inherited from Transaction)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このトランザクションと、指定したオブジェクトが等しいかどうかを判断します。Determines whether this transaction and the specified object are equal.

(Inherited from Transaction)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

(Inherited from Transaction)
GetPromotedToken() GetPromotedToken() GetPromotedToken() GetPromotedToken()

トランザクションを昇格するときに、Promote メソッドで返される byte[] を取得します。Gets the byte[] returned by the Promote method when the transaction is promoted.

(Inherited from Transaction)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions)

昇格およびトランザクションに参加する 2 フェーズ コミットをサポートする永続的リソース マネージャーを参加させます。Promotes and enlists a durable resource manager that supports two phase commit to participate in a transaction.

(Inherited from Transaction)
Rollback() Rollback() Rollback() Rollback()

ロールバック (中止) トランザクション。Rolls back (aborts) the transaction.

(Inherited from Transaction)
Rollback(Exception) Rollback(Exception) Rollback(Exception) Rollback(Exception)

ロールバック (中止) トランザクション。Rolls back (aborts) the transaction.

(Inherited from Transaction)
SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid)

MSDTC でないプロモーターによって生成される分散トランザクションの識別子を設定します。Sets the distributed transaction identifier generated by the non-MSDTC promoter.

(Inherited from Transaction)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

明示的なインターフェイスの実装

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

プロパティ

IsolationLevel IsolationLevel IsolationLevel IsolationLevel

トランザクションの分離レベルを取得します。Gets the isolation level of the transaction.

(Inherited from Transaction)
PromoterType PromoterType PromoterType PromoterType

トランザクションを昇格するときに、Promote メソッドで返される byte[] の形式を一意に識別します。Uniquely identifies the format of the byte[] returned by the Promote method when the transaction is promoted.

(Inherited from Transaction)
TransactionInformation TransactionInformation TransactionInformation TransactionInformation

トランザクションに関する追加情報を取得します。Retrieves additional information about a transaction.

(Inherited from Transaction)

イベント

TransactionCompleted TransactionCompleted TransactionCompleted TransactionCompleted

トランザクションが完了したことを示します。Indicates that the transaction is completed.

(Inherited from Transaction)

適用対象

スレッド セーフ

この型はスレッド セーフです。This type is thread safe.

こちらもご覧ください