言語

RunningPackagesEnumerator.Current プロパティ

定義

コレクションから現在の RunningPackage オブジェクトを返します。

public:
 property Microsoft::SqlServer::Dts::Runtime::RunningPackage ^ Current { Microsoft::SqlServer::Dts::Runtime::RunningPackage ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.RunningPackage Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.RunningPackage
Public ReadOnly Property Current As RunningPackage

プロパティ値

RunningPackage オブジェクト。

以下のコード例は、実行中のパッケージを反復する列挙子を作成します。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace RunningPackages  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application app = new Application();  
            RunningPackages pkgs = app.GetRunningPackages("YOURSERVER");  

            int pkgsRunning = pkgs.Count;  
            Console.WriteLine("Packages before stop: " + pkgsRunning);  

            // Get the RunningPackages collection from the package.  
            RunningPackages runPkgs = app.GetRunningPackages("YOURSERVER ");  

            //Create the Enumerator.  
            RunningPackagesEnumerator myEnumerator = runPkgs.GetEnumerator();  

            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
            Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.PackageDescription);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace RunningPackages  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim app As Application =  New Application()   
            Dim pkgs As RunningPackages =  app.GetRunningPackages("YOURSERVER")   

            Dim pkgsRunning As Integer =  pkgs.Count   
            Console.WriteLine("Packages before stop: " + pkgsRunning)  

            ' Get the RunningPackages collection from the package.  
            Dim runPkgs As RunningPackages =  app.GetRunningPackages("YOURSERVER ")   

            'Create the Enumerator.  
            Dim myEnumerator As RunningPackagesEnumerator =  runPkgs.GetEnumerator()   

            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
            Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
        End Sub  
    End Class  
End Namespace  

注釈

列挙子が作成されるか、Resetメソッドに呼び出した後、列挙子がMoveNextプロパティの値を読み取る前に、Currentメソッドを呼び出してコレクションの最初の要素に進めなければなりません;そうでなければ、Currentは未定義となり例外を投げ出します。

Current また、 MoveNext の最後の呼び出しが false返された場合も例外がスローされます。これはコレクションの末尾を示します。

Currentは列挙子の位置を移動せず、CurrentまたはMoveNextが呼び出されるまで、Resetの連続した呼び出しは同じオブジェクトを返します。

列挙子は、コレクションが変更されない限り有効なままです。 コレクションに要素の追加、修正、削除などの変更が加えられると、列挙子は無効化され回復不能になります。そのため、次に MoveNextReset に電話をかけると InvalidOperationExceptionが投げられます。 しかし、 MoveNextCurrentの呼び出し間でコレクションが変更されると、 Current は列挙子が無効化されていても、設定された要素を返します。

適用対象