Variables.Locked Property

A Boolean indicating whether the variables in the Variables collection are locked.

命名空間: Microsoft.SqlServer.Dts.Runtime
組件: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

語法

'宣告
Public ReadOnly Property Locked As Boolean
public bool Locked { get; }
public:
property bool Locked {
    bool get ();
}
/** @property */
public boolean get_Locked ()
public function get Locked () : boolean

屬性值

true indicates that the collection is locked. A value of false indicates that the collection is unlocked.

備註

The Variables collection contains a Locked property that indicates whether a variable dispenser collection of variables is locked (true) or unlocked (false). The reason to review this property is that some tasks explicitly release locks to the variables they are using, and calling Unlock twice throws an error. Therefore, you should use Locked property determine whether the dispensed collection is locked before calling Unlock.

範例

The following code example locks the variable collection when GetVariables is called. The example then determines whether the collection is locked and, if the collection is locked, calls 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

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

Variables Class
Variables Members
Microsoft.SqlServer.Dts.Runtime Namespace