HttpApplicationState.Lock 方法

定義

鎖定對 HttpApplicationState 變數的存取,以加速存取的同步處理。Locks access to an HttpApplicationState variable to facilitate access synchronization.

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

範例

下列範例會使用 Lock 方法和 UnLock 方法,以防止其他會話變更兩個應用程式變數的值,直到本機會話變更它們為止。The following example uses the Lock method and UnLock method to prevent other sessions from changing the value of two application variables until after the local session has changed them.

Application.Lock();
Application["MyCode"] = 21;
Application["MyCount"] = Convert.ToInt32(Application["MyCount"]) + 1;
Application.UnLock();

Application.Lock()
Application("MyCode") = 21
Application("MyCount") = Convert.ToInt32(Application("MyCount")) + 1
Application.UnLock()

備註

HttpApplicationState類別會使用和屬性執行自動鎖定和解除鎖定,以及、、、 AllKeys Count Add Clear Get GetKeyRemove RemoveAtSet 方法。The HttpApplicationState class performs automatic locking and unlocking with the AllKeys and Count properties and the Add, Clear, Get, GetKey, Remove, RemoveAt and Set methods. 但是, Lock UnLock 當您有一系列的作業時,請明確使用和方法,可能會更有效率。However, explicitly using the Lock and UnLock methods when you have a series of operations may be more efficient.

適用於

另請參閱