Transaction.EnlistVolatile Transaction.EnlistVolatile Transaction.EnlistVolatile Transaction.EnlistVolatile Method

定義

トランザクションに参加する揮発性リソース マネージャーを参加させます。Enlists a volatile resource manager to participate in a 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.

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.

注釈

揮発性リソースマネージャーは、障害から復旧して、参加しているトランザクションを完了することはできません。Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. 揮発性リソースと持続性のあるリソースの詳細、およびリソースの参加方法については、「リソースマネージャーの実装」を参照してください。For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. リソースマネージャーがコミット通知に応答してコミットを準備する方法の詳細については、「単一フェーズおよび複数フェーズでのトランザクションのコミット」を参照してください。For more information on how a resource manager responds to commit notification and prepare the commit, see Committing A Transaction In Single-Phase and Multi-Phase.

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.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::IEnlistmentNotification ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.IEnlistmentNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (notification As IEnlistmentNotification, options As EnlistmentOptions) As Enlistment

パラメーター

enlistmentNotification
IEnlistmentNotification IEnlistmentNotification IEnlistmentNotification IEnlistmentNotification

2 フェーズ コミット通知を受信する IEnlistmentNotification インターフェイスを実装するオブジェクト。An object that implements the IEnlistmentNotification interface to receive two-phase commit notifications.

enlistmentOptions
EnlistmentOptions EnlistmentOptions EnlistmentOptions EnlistmentOptions

リソース マネージャーが、準備フェーズ中に追加の処理を実行する場合 EnlistDuringPrepareRequiredEnlistDuringPrepareRequired if the resource manager wants to perform additional work during the prepare phase.

戻り値

参加リストについて記述している Enlistmentオブジェクト。An Enlistment object that describes the enlistment.

次の例は、インターフェイスのIEnlistmentNotification実装と、 EnlistVolatileメソッドを使用して、オブジェクトをトランザクションの参加要素として参加させる方法を示しています。The following example shows an implementation of IEnlistmentNotification interface, as well as enlisting the object as a participant in a transaction using the EnlistVolatile method.

static void Main(string[] args)
{
	try
	{
		using (TransactionScope scope = new TransactionScope())
		{
		
			//Create an enlistment object
			myEnlistmentClass myElistment = new myEnlistmentClass();

			//Enlist on the current transaction with the enlistment object
			Transaction.Current.EnlistVolatile(myElistment, EnlistmentOptions.None);

			//Perform transactional work here.

			//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'))
				{
					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;
	}
}

class myEnlistmentClass : IEnlistmentNotification
{
	public void Prepare(PreparingEnlistment preparingEnlistment)
	{
		Console.WriteLine("Prepare notification received");

		//Perform transactional work

		//If work finished correctly, reply prepared
		preparingEnlistment.Prepared();

		// otherwise, do a ForceRollback
		preparingEnlistment.ForceRollback();
	}

	public void Commit(Enlistment enlistment)
	{
		Console.WriteLine("Commit notification received");

		//Do any work necessary when commit notification is received

		//Declare done on the enlistment
		enlistment.Done();
	}

	public void Rollback(Enlistment enlistment)
	{
		Console.WriteLine("Rollback notification received");

		//Do any work necessary when rollback notification is received

		//Declare done on the enlistment
		enlistment.Done();
	}

	public void InDoubt(Enlistment enlistment)
	{
		Console.WriteLine("In doubt notification received");

		//Do any work necessary when indout notification is received
		
		//Declare done on the enlistment
		enlistment.Done();
	}
}
	Public Shared Sub Main()
		Try
			Using scope As TransactionScope = New TransactionScope()

				'Create an enlistment object
				Dim myEnlistmentClass As New EnlistmentClass

				'Enlist on the current transaction with the enlistment object
				Transaction.Current.EnlistVolatile(myEnlistmentClass, EnlistmentOptions.None)

				'Perform transactional work here.

				'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
End Class

Public Class EnlistmentClass
	Implements IEnlistmentNotification

	Public Sub Prepare(ByVal myPreparingEnlistment As PreparingEnlistment) Implements System.Transactions.IEnlistmentNotification.Prepare
		Console.WriteLine("Prepare notification received")

		'Perform transactional work

		'If work finished correctly, reply with prepared
		myPreparingEnlistment.Prepared()
	End Sub

	Public Sub Commit(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Commit
		Console.WriteLine("Commit notification received")

		'Do any work necessary when commit notification is received

		'Declare done on the enlistment
		myEnlistment.Done()
	End Sub

	Public Sub Rollback(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Rollback
		Console.WriteLine("Rollback notification received")

		'Do any work necessary when rollback notification is received

		'Declare done on the enlistment
		myEnlistment.Done()
	End Sub

	Public Sub InDoubt(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.InDoubt
		Console.WriteLine("In doubt notification received")

		'Do any work necessary when indout notification is received

		'Declare done on the enlistment
		myEnlistment.Done()
	End Sub
End Class

注釈

揮発性リソースマネージャーは、障害から復旧して、参加しているトランザクションを完了することはできません。Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. トランザクションの永続参加リストを取得するには、 EnlistDurableメソッドを使用します。To obtain a durable enlistment in a transaction, use the EnlistDurable method.

このメソッドを使用してトランザクションに参加するために参加しているリソースマネージャーは、 IEnlistmentNotificationインターフェイスで定義されたメソッドに対応する2フェーズコミット通知を受け取ります。Resource managers enlisted for participation in a transaction through this method receive two phase commit notifications that correspond to the methods defined on the IEnlistmentNotification interface.

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.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::ISinglePhaseNotification ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.ISinglePhaseNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (notification As ISinglePhaseNotification, options As EnlistmentOptions) As Enlistment

パラメーター

singlePhaseNotification
ISinglePhaseNotification ISinglePhaseNotification ISinglePhaseNotification ISinglePhaseNotification

ISinglePhaseNotification インターフェイスを実装し、単一フェーズ コミットと 2 フェーズ コミットの通知を受け取ることができる必要のあるオブジェクト。An object that implements the ISinglePhaseNotification interface that must be able to receive single phase commit and two phase commit notifications.

enlistmentOptions
EnlistmentOptions EnlistmentOptions EnlistmentOptions EnlistmentOptions

リソース マネージャーが、準備フェーズ中に追加の処理を実行する場合 EnlistDuringPrepareRequiredEnlistDuringPrepareRequired if the resource manager wants to perform additional work during the prepare phase.

戻り値

参加リストについて記述している Enlistmentオブジェクト。An Enlistment object that describes the enlistment.

注釈

揮発性リソースマネージャーは、障害から復旧して、参加しているトランザクションを完了することはできません。Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. トランザクションの永続参加リストを取得するには、 EnlistDurableメソッドを使用します。To obtain a durable enlistment in a transaction, use the EnlistDurable method. 揮発性リソースと持続性のあるリソースの詳細、およびリソースの参加方法については、「リソースマネージャーの実装」を参照してください。For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. リソースマネージャーがコミット通知に応答してコミットを準備する方法の詳細については、「単一フェーズおよび複数フェーズでのトランザクションのコミット」を参照してください。For more information on how a resource manager responds to commit notification and prepare the commit, see Committing A Transaction In Single-Phase and Multi-Phase.

Resource manager の実装がこのメソッドに参加している場合でも、1つのフェーズコミットを受信する保証はないことに注意してください。You should note that even when your resource manager implementation enlists with this method, it is not guaranteed that it receives a single phase commit. トランザクションマネージャーは、代わりに2フェーズコミット通知を送信できます。The transaction manager can still send two phase commit notifications instead. 単一フェーズコミットの最適化の詳細については、「単一フェーズコミットを使用した最適化」と「昇格可能な単一フェーズ通知」を参照してください。For more information on the single phase commit optimization, see Optimization Using Single Phase Commit and Promotable Single Phase Notification.

こちらもご覧ください

適用対象