Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application.lock

Status
Not open for further replies.

Jeremy21b

Technical User
Jul 7, 2002
127
CA
Ok I have a question about application.lock
I want to put infrequently changed data into application variables. I also have userid as an application variable which is updated everytime someone registers. I heard that locking the application variable, makes all application level variables inaccessible. In other words, everytime someone registers, the other application variables won't be available for that split second it takes to update the userid. Is this true? It might not be a problem right now, but as the website gets busier this could become an issue.
 
Application.Lock
Microsoft explanation
Code:
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 Unlock method explicitly, the server unlocks the locked Application object when the .asp file ends or times out.

Example

<% 
Application.Lock 
Application(&quot;NumVisits&quot;) = Application(&quot;NumVisits&quot;) + 1 
Application(&quot;datLastVisited&quot;) = Now() 
Application.Unlock 
%> 
 
This application page has been visited 
<%= Application(&quot;NumVisits&quot;) %>  times!
 
In the preceding example the Lock method prevents more than one client from accessing the variable NumVisits at a time. If the application had not been locked, two clients could try to increment the variable NumVisits simultaneously.

________
George, M
 
In other hands using Lock makes Application requests for one variable to be Queued.

________
George, M
 
ok I knew that it blocked people from updating the same value at the same time. I just read somewhere else that made it sound like every application level variable would not be accessible when just 1 application variable was being updated. So there shouldn't be problems with other pages accessing different application variables during an update to the userid? Also are there are drawbacks to using a lot of application variables. Is there anything I'd have to worry about if I put all of our product models in application variable arrays? The only drawback I see is the loss of dynamic listings, which could be overcome by updating the arrays periodically.
 
Try to keep the Application Object as much as clean (wich means dont store loads of data in it, for example an Recordset object)
If you store simple data or arrays, should be ok, but you ave to remember that when the IIS service it's stoped the data it's lost, try to save data on Application_OnEnd even if you need to save.

For storin user related data you should use Session object.

________
George, M
 
Well its all data that we have in our database, so it wouldn't be lost when IIS is stopped. I just want to cut down on some unnecessary SQL connections. I thought it might be more efficient to store a bunch of basic arrays rather than request that data from SQL everytime. It would be easy enough to check if the application variable exists and repopulate it if necessary.
 
If you gonna use the application for an intranet then it should be ok to store data in Applocation.
But ISP woudnt like that :)

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top