IEnlistmentNotification インターフェイス
アセンブリ: System.Transactions (system.transactions.dll 内)


リソース マネージャがトランザクションに参加するには、トランザクション マネージャを介してトランザクションに参加する必要があります。Transaction クラスは、この機能を提供する、名前が Enlist から始まる一連のメソッドを定義します。異なる Enlist メソッドは、リソース マネージャが持つ異なる種類の参加リストにそれぞれ対応しています。
このクラスは、参加の登録時にトランザクション マネージャに対して 2 フェーズ コミットの通知コールバックを行うために、リソース マネージャが実装する必要のあるインターフェイスを示します。リソース マネージャの IEnlistmentNotification インターフェイスの各実装ごとに、リソースが揮発性であるか永続的であるかに応じて、Transaction クラスの EnlistVolatile メソッドまたは EnlistDurable メソッドを使用してリソース マネージャを参加させる必要があります。参加リストと 2PC の詳細については、それぞれ「トランザクションへの参加要素としてのリソースの登録」および「単一フェーズおよびマルチフェーズでのトランザクションのコミット」を参照してください。
トランザクション マネージャは、次のメソッドを使用して、2 フェーズ コミット プロトコルの異なるフェーズで、参加オブジェクトに通知を行います。
参加オブジェクトのこのメソッドは、参加要素がトランザクションをコミットできるかどうかをトランザクション マネージャが参加要素に問い合わせる際に、トランザクションの最初のフェーズでトランザクション マネージャによるコールバックとして使用されます。 | |
参加オブジェクトのこのメソッドは、トランザクションがコミットされた場合、トランザクションの第 2 フェーズでトランザクション マネージャによるコールバックとして使用されます。 | |
参加オブジェクトのこのメソッドは、トランザクションが中止 (つまりロールバック) された場合、トランザクションの第 2 フェーズでトランザクション マネージャによるコールバックとして使用されます。 |

次の例では、このインターフェイスを実装し、EnlistVolatile メソッドを使用して、オブジェクトを参加要素としてトランザクションに参加させます。
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
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(); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


IEnlistmentNotification メソッド

名前 | 説明 | |
---|---|---|
![]() | Commit | トランザクションのコミット中であることを参加オブジェクトに通知します。 |
![]() | InDoubt | トランザクションのステータスが未決定であることを参加オブジェクトに通知します。 |
![]() | Prepare | トランザクションのコミットの準備中であることを参加オブジェクトに通知します。 |
![]() | Rollback | トランザクションのロールバック (中止) 中であることを参加オブジェクトに通知します。 |

IEnlistmentNotification メンバ
参加の登録時に、トランザクション マネージャに対して 2 フェーズ コミットの通知コールバックを行うために、リソース マネージャが実装する必要のあるインターフェイスを示します。
IEnlistmentNotification データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | Commit | トランザクションのコミット中であることを参加オブジェクトに通知します。 |
![]() | InDoubt | トランザクションのステータスが未決定であることを参加オブジェクトに通知します。 |
![]() | Prepare | トランザクションのコミットの準備中であることを参加オブジェクトに通知します。 |
![]() | Rollback | トランザクションのロールバック (中止) 中であることを参加オブジェクトに通知します。 |

- IEnlistmentNotificationのページへのリンク