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。