LOTUSSCRIPT LANGUAGE
Example 1:
Sub Initialize
Dim Sess As New NotesSession
Dim Doc As NotesDocument
Dim Count As NotesItem
Set Doc = Sess.SavedData
Set count = Doc.GetFirstItem("WebHits")
If count Is Nothing Then
Set count = New NotesItem(Doc, "WebHits", 0)
End If
count.Values = count.Values(0) + 1
Call Doc.Save(True,False)
End Sub
The second example demonstrates how CodeLock can avoid the problem presented in Example 1. You create and make sure you have a secure lock before you read and make changes to the count, and when you are done, you release the lock.
Example 2:
Dim Status As Integer
Dim LockID As Integer
Dim others As Integer
' Creating a Lock ID or getting the Lock ID
' For the event of "WebSiteHits"
LockID = Createlock("WebSiteHits")
' Infinite loop that can only be exited
' when this agent has a successfull
' lock. An unsuccessfull lock means
' that this agent is presently being
' run by someone else.
Do While True
If Codelock(LockID) Then
Exit Do ' We finally have a lock, exiting Loop
Loop
' Once completed, release and
' destroy this lock so another
' run of this agent can continue.
Status = CodeUnlock(LockID)
Status = DestroyLock(LockID)