Inhaltsverzeichnis reduzieren
Inhaltsverzeichnis erweitern


Gets the current element in the collection.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public DtsEventHandler Current { get; }


Typ: Microsoft.SqlServer.Dts.Runtime..::..DtsEventHandler
The current element in the collection.

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before reading the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an InvalidOperationException. If the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

The following code sample creates two event handlers for the package. For one event handler, two tasks are added. Then a DtsEventHandlerEnumerator is created, and uses the Current and MoveNext methods to navigate over the collection.

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);

Sample Output:

The collection contains the following values:

[0] OnError

[1] OnWarning


© 2015 Microsoft