コレクション内にある現在の要素を取得します。
名前空間: Microsoft.SqlServer.Dts.Runtime
アセンブリ: Microsoft.SqlServer.ManagedDTS (microsoft.sqlserver.manageddts.dll 内)
構文
'宣言
Public ReadOnly Property Current As DtsEventHandler
public DtsEventHandler Current { get; }
public:
property DtsEventHandler^ Current {
DtsEventHandler^ get ();
}
/** @property */
public DtsEventHandler get_Current ()
public function get Current () : DtsEventHandler
プロパティ値
コレクション内にある現在の要素です。
解説
列挙子を作成した後や Reset メソッドを呼び出した後は、Current プロパティの値を読み取る前に、MoveNext メソッドを呼び出して列挙子をコレクションの先頭の要素に進めておく必要があります。そうしないと、Current は未定義となり、例外がスローされます。
また、MoveNext の最後の呼び出しでコレクションの末尾を示す false が返された場合、Current を呼び出すと例外がスローされます。
Current は列挙子の位置を移動しません。Current を連続して呼び出すと、MoveNext または Reset が呼び出されるまで同じオブジェクトが返されます。
列挙子は、コレクションが変更されない限り有効です。要素の追加、変更、削除など、コレクションに変更が加えられた場合は、列挙子は無効になり回復できなくなります。そのため、次の MoveNext または Reset の呼び出しで InvalidOperationException がスローされます。MoveNext を呼び出してから Current を呼び出すまでの間にコレクションが変更された場合、列挙子は無効になっていても、Current は設定されている要素を返します。
使用例
次のコード サンプルでは、パッケージに 2 つのイベント ハンドラを作成します。1 つのイベント ハンドラに 2 つのタスクが追加されます。次に、DtsEventHandlerEnumerator を作成し、Current と MoveNext メソッドを使用してコレクションを移動します。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.SendMailTask;
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask;
namespace DtsEventHandler_API
{
class Program
{
static void Main(string[] args)
{
Package pkg = new Package();
// Set up a DtsEventHandler for the OnError event of the package.
DtsEventHandler dtsEHOE = (DtsEventHandler)pkg.EventHandlers.Add("OnError");
DtsEventHandler dtsEHW = (DtsEventHandler)pkg.EventHandlers.Add("OnWarning");
// When an OnError Event occurs, the Executables collection contains
// the items to run. For this example, there will be a SendMailtTask
// and a BulkInsertTask with a precedence constraint between them.
Executable dtsEH1 = dtsEHOE.Executables.Add("STOCK:SendMailTask");
TaskHost th = (TaskHost)dtsEH1;
SendMailTask smTask = (SendMailTask)th.InnerObject;
smTask.Subject = "Send Mail task";
// Add a second executable to the DtsEventHandler.
Executable dtsEH2 = dtsEHOE.Executables.Add("STOCK:BulkInsertTask");
TaskHost th2 = (TaskHost)dtsEH2;
//Create the Enumerator. Since we added the DtsEventhandler to the
// package, then that's where to get the EventHandlers collection.
DtsEventHandlerEnumerator myEnum = pkg.EventHandlers.GetEnumerator();
Console.WriteLine("The collection contains the following values:");
int i = 0;
while ((myEnum.MoveNext()) && (myEnum.Current != null))
Console.WriteLine("[{0}] {1}", i++, myEnum.Current.Name);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.SendMailTask
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask
Namespace DtsEventHandler_API
Class Program
Shared Sub Main(ByVal args() As String)
Dim pkg As Package = New Package()
' Set up a DtsEventHandler for the OnError event of the package.
Dim dtsEHOE As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)
Dim dtsEHW As DtsEventHandler = CType(pkg.EventHandlers.Add("OnWarning"), DtsEventHandler)
' When an OnError Event occurs, the Executables collection contains
' the items to run. For this example, there will be a SendMailtTask
' and a BulkInsertTask with a precedence constraint between them.
Dim dtsEH1 As Executable = dtsEHOE.Executables.Add("STOCK:SendMailTask")
Dim th As TaskHost = CType(dtsEH1, TaskHost)
Dim smTask As SendMailTask = CType(th.InnerObject, SendMailTask)
smTask.Subject = "Send Mail task"
' Add a second executable to the DtsEventHandler.
Dim dtsEH2 As Executable = dtsEHOE.Executables.Add("STOCK:BulkInsertTask")
Dim th2 As TaskHost = CType(dtsEH2, TaskHost)
'Create the Enumerator. Since we added the DtsEventhandler to the
' package, then that's where to get the EventHandlers collection.
Dim myEnum As DtsEventHandlerEnumerator = pkg.EventHandlers.GetEnumerator()
Console.WriteLine("The collection contains the following values:")
Dim i As Integer = 0
While (myEnum.MoveNext()) &&(myEnum.Current <> Nothing)
Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
End While
End Sub
End Class
End Namespace
サンプルの出力 :
The collection contains the following values:
[0] OnError
[1] OnWarning
スレッド セーフ
この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム
開発プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
対象プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
参照
関連項目
DtsEventHandlerEnumerator Class
DtsEventHandlerEnumerator Members
Microsoft.SqlServer.Dts.Runtime Namespace