语言

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返回同一对象,直到调用或MoveNextReset调用。

只要集合保持不变,枚举器就保持有效。 如果对集合进行了更改,比如添加、修改或删除元素,枚举器将失效并无法恢复;因此,下一次调用 MoveNextReset 会抛出 InvalidOperationException。 然而,如果集合在调用和MoveNextCurrent之间被修改,Current即使枚举器已被失效,集合返回了它所设定的元素。

适用于