Export (0) Print
Expand All

Application.Lock Method

IIS 6.0

The Lock method blocks other clients from modifying the variables stored in the Application object, ensuring that only one client at a time can alter or access the Application variables. If you do not call the Application.Unlock method explicitly, the server unlocks the locked Application object when the .asp file ends or times out.

Lock(
)

This method has no parameters.

This method has no return values.

A lock on the Application object persists for a very short time because the application object is unlocked when the page completes processing or times out.

If one page locks the application object and a second page tries to do the same while the first page still has it locked, the second page will wait for the first to finish, or until the Server.ScriptTimeout limit is reached. If the Server.ScriptTimeout limit is reached, the following ASP error is returned which cannot be captured:

HTTP 500.100 - Internal Server Error - ASP error  
Internet Information Services 

Active Server Pages, ASP 0113 (0x80004005)  
The maximum amount of time for a script to execute was exceeded.  
You can change this limit by specifying a new value for the property  
Server.ScriptTimeout or by changing the value in the IIS administration tools.

To reduce the possibility of having an ASP page time out, write a COM+ object that uses the COM+ ObjectContext object to update the Application collection, and then call the COM+ object from an ASP page. COM+ objects execute slightly faster than ASP pages. For more information, see Using the COM+ ObjectContext Object to Access the ASP Built-in Objects

NoteNote:

A page does not need to lock the application object to edit the application collection. If one page tries to edit the application collection without locking and a second page also tries to edit the collection, no error is sent by IIS and the Application object ends up in an inconsistent state.

Applies To

In the following example, the Lock method prevents more than one client at a time from accessing the variable NumVisits. If the application had not been locked, two clients could simultaneously try to increment the variable NumVisits.


<%@ Language="VBScript" %> 
<% 
Application.Lock  
Application("NumVisits") = Application("NumVisits") + 1  
Application("datLastVisited") = Now()  
Application.Unlock  
%>  

This application page has been visited  
<%= Application("NumVisits") %>  times! 

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

Show:
© 2014 Microsoft