Variables.Unlock 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
釋放變數集合上的鎖定,並將變數集合的狀態標示為無效或未知。
public:
void Unlock();
public void Unlock ();
member this.Unlock : unit -> unit
Public Sub Unlock ()
範例
下列程式碼範例會在呼叫時鎖定變數集合 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
備註
這個方法是用來解除鎖定使用類別鎖定的變數 VariableDispenser 。 VariableDispenser不表達變數集合時,會在清單中追蹤集合。 當呼叫變數分配器的工作執行完成時,所有分配的集合都會自動解除鎖定。 因此,如果自動解除鎖定適用于您的目的,而且當工作完成時,如果自動解除鎖定,您就不需要呼叫 Unlock 方法。 不過,基於效能考慮,有時可能會想要儘快將變數解除鎖定。 明確呼叫這個方法會 Unlock 將變數解除鎖定。
屬性會傳回的值,表示已解除配置的 Locked 集合已 false 解除鎖定。 的值 true 表示變數集合仍然鎖定。 呼叫 Unlock 兩次會導致錯誤; 因此,在某些情況下,您可能必須先檢查這個屬性的值,然後再決定是否要呼叫 Unlock 。