VariableDispenser.LockForRead(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将变量添加到要锁定用于只读访问的变量列表。
public:
void LockForRead(System::String ^ variable);
public void LockForRead (string variable);
member this.LockForRead : string -> unit
Public Sub LockForRead (variable As String)
参数
- variable
- String
要添加到列表中以锁定用于只读访问的变量的名称。
示例
下面的代码示例创建一个 VariableDispenser 系统变量,并将两个系统变量添加到锁定以供读取的列表,并将一个系统变量添加到锁定以供写入的列表。 然后,调用该 GetVariables 变量来锁定集合中的所有三个变量,并释放列表并可用于新变量。
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.GetVariables(ref vars);
// Verify that the variable is locked before unlocking.
Console.WriteLine("Variables are locked? {0}", vars.Locked);
foreach (Variable myVar in vars)
{
Console.WriteLine("Name {0}", myVar.Name);
Console.WriteLine("Description {0}", myVar.Description);
Console.WriteLine();
}
// Use Contains to determine whether indexing can be used.
Boolean pkgName = variableDispenser.Contains("PackageName");
String qName = variableDispenser.GetQualifiedName("PackageName");
Console.WriteLine("Contains is valid? {0}", pkgName);
Console.WriteLine("Fully qualified name is: {0}", qName);
vars.Unlock();
Console.WriteLine("Variables are locked? {0}", vars.Locked);
}
}
}
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.GetVariables( vars)
' Verify that the variable is locked before unlocking.
Console.WriteLine("Variables are locked? {0}", vars.Locked)
Dim myVar As Variable
For Each myVar In vars
Console.WriteLine("Name {0}", myVar.Name)
Console.WriteLine("Description {0}", myVar.Description)
Console.WriteLine()
Next
' Use Contains to determine whether indexing can be used.
Dim pkgName As Boolean = variableDispenser.Contains("PackageName")
Dim qName As String = variableDispenser.GetQualifiedName("PackageName")
Console.WriteLine("Contains is valid? {0}", pkgName)
Console.WriteLine("Fully qualified name is: {0}", qName)
vars.Unlock()
Console.WriteLine("Variables are locked? {0}", vars.Locked)
End Sub
End Class
End Namespace
示例输出:
Variables are locked? True
Name OfflineMode
Description The offline mode currently set for the package
Name PackageName
Description The package name
Contains is valid? True
Fully qualified name is: System::PackageName
Variables are locked? False
注解
此方法在首次调用时创建一个列表,并将给定变量添加到列表中。 在后续调用中,变量将添加到现有列表中。 此方法实际上不会锁定变量。 创建所需变量的列表后,调用 GetVariables 以锁定此列表中找到的变量。 调用之前LockForWriteGetVariables可以进行任意数量的调用LockForRead。
备注
多个客户端可以同时获取变量上的只读锁。
若要在完成后清除成功的锁,请调用 Unlock。