Freigeben über


Unlock-Methode

Releases the locks on the variables collection and flags the state of the variables collection as invalid or unknown.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

Syntax

'Declaration
Public Sub Unlock
'Usage
Dim instance As Variables

instance.Unlock()
public void Unlock()
public:
void Unlock()
member Unlock : unit -> unit 
public function Unlock()

Hinweise

This method is used to unlock variables that were locked by using the VariableDispenser class. When VariableDispenser dispenses a variables collection, it keeps track of the collection in a list. When the task that called the variable dispenser finishes executing, all dispensed collections are automatically unlocked. Therefore, if automatic unlocking is suitable for your purposes, and if automatic unlocking occurred when the task completed, you do not need to call the Unlock method. However, it is sometimes desirable to unlock variables as soon as possible for performance reasons. An explicit call to this Unlock method unlocks the variables.

The Locked property returns a value of false to indicate that a dispensed collection has already been unlocked. A value of true indicates that the variable collection is still locked. Calling Unlock twice causes an error; therefore, in certain situations you may have to check the value of this property before deciding whether to call Unlock.

Beispiele

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