共用方式為


VariableDispenser.Reset Method

Definition

Clears both the read-only list and read/write list when the call to GetVariables(Variables) fails.

public:
 void Reset();
public void Reset ();
member this.Reset : unit -> unit
Public Sub Reset ()

Examples

The following code example locks a collection of variables, and then determines whether the variable collection is locked before unlocking them. If the lock failed, then Reset is called.

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);             
            // Determine whether the variable collection is locked.  
            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.GetVariables( vars)  
            ' Determine whether the variable collection is locked.  
            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  

Remarks

This method can be used to clear the read-only list and the read/write lock list after a call to GetVariables has failed. If a call to GetVariables fails, the lock lists are not cleared and therefore, if you call GetVariables again, an attempt will be made to lock the same variables. If you want to retry locking the same variables, call GetVariables again without calling Reset first. Or, you can choose to release the lists by using this method and abandoning the operation until all required variables are available and can be locked at once.

Additionally, the Reset method is used if you receive a failure from GetVariables and you want to lock a completely different and unrelated set of variables next. You would call Reset to clear the lock lists, and then refill the lock lists by using the LockForRead, LockForWrite, LockOneForRead, and LockOneForWrite methods.

Applies to