Variables.Locked 属性

定义

一个布尔值,指示集合中的 Variables 变量是否处于锁定状态。

public:
 property bool Locked { bool get(); };
public bool Locked { get; }
member this.Locked : bool
Public ReadOnly Property Locked As Boolean

属性值

true 表示集合已锁定。 值为 false 表示集合已解锁。

示例

以下代码示例在调用变量集合时 GetVariables 锁定变量集合。 然后,该示例确定集合是否已锁定,如果已锁定集合,则调用 Unlock

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

namespace Microsoft.SqlServer.SSIS.Sample  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            Variables vars = null;  
            VariableDispenser variableDispenser = pkg.VariableDispenser;  
            variableDispenser.LockForRead("System::PackageName");  
            variableDispenser.LockForRead("System::OfflineMode");  
            variableDispenser.LockForWrite("System::InteractiveMode");  
            variableDispenser.GetVariables(ref vars);             
            // Determine whether the variable collection is locked before unlocking.  
            Boolean isLocked = vars.Locked;  

            // Verify the value of vars.Locked. If the lock failed,  
            // call Reset.  
            if (isLocked)  
            {  
                vars.Unlock();  
            }  
            else  
            {  
                variableDispenser.Reset();  
            }  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Microsoft.SqlServer.SSIS.Sample  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            Dim vars As Variables =  Nothing   
            Dim variableDispenser As VariableDispenser =  pkg.VariableDispenser   
            variableDispenser.LockForRead("System::PackageName")  
            variableDispenser.LockForRead("System::OfflineMode")  
            variableDispenser.LockForWrite("System::InteractiveMode")  
            variableDispenser.GetVariables( vars)  
            ' Determine whether the variable collection is locked before unlocking.  
            Dim isLocked As Boolean =  vars.Locked   

            ' Verify the value of vars.Locked. If the lock failed,  
            ' call Reset.  
            If isLocked = True Then  
                vars.Unlock()  
            Else   
                variableDispenser.Reset()  
            End If  
        End Sub  
    End Class  
End Namespace  

注解

Variables 集合包含一个 Locked 属性,该属性指示变量分配器集合是锁定 () true 还是解锁 () false 。 查看此属性的原因是,某些任务显式释放它们正在使用的变量的锁,并调用 Unlock 两次会引发错误。 因此,应使用 Locked 属性来确定分配集合在调用 Unlock之前是否已锁定。

适用于