ALP Application.Lock and Unlock methods

Lock and Unlock methods are used for synchronization. Lock adds a lock to the application object and all other calls to it (from other threads/script/pages) will wait until Unlock is called.

Syntax:

  1. Application.Lock()
    Application.Unlock()

It is important to use these methods when changing Application Contents collection because ALP supports many threads. Every IE window opened from the same process shares the same Application object (in one application). Thus you may have several running scripts at once in different windows or/and frames. Whenever you expect that certain code may suffer problems from inconsistent information in a particular Application variable you should use Lock/Unlock to serialize access to it. 

Samples:

<% Application.Lock() %>
<% Application("UserName") = strUser %>
<% Application.Unlock() %>

Remarks:

It is recommended to use On Error Resume Next statements for the part of the code that uses Lock/Unlock methods to guarantee that the Application will be unlocked properly even if the code errors for some reason. ALP 1.2 and later will unlock the Application whenever a page finishes, but this is only an emergency solution and the developers should take care to not rely on it when possible.

To optimize the application you should minimize the time in which the Application is locked as much as possible.

Applies to: Application object

See also: Application.Contents, VarDictionary

newObjects Copyright 2001-2006 newObjects [ ]