Variables.Locked 屬性

定義

布林值,指出集合中的變數是否 Variables 已鎖定。

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

屬性值

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

適用於