Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using SyncLock
Message
From
15/01/2011 09:44:53
 
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01496120
Message ID:
01496281
Views:
39
>Can't pin it down but that feels a bit risky in that lFirstHit itself is not thread safe. And I'm also not sure whether taking a lock on a property of oApp itself is good. Best practice might be something like this:
If Not oApp.lInitialize Then
>        SyncLock locker
>            'Check again inside safe section
>            If Not oApp.lInitialize Then
>                'Do stuff
>                oApp.lInitialize = True
>            End If
>        End SyncLock
>  End If
>'Where locker is:
>Private Shared locker As New [Object]()
No guarantees :-}
>
>UPDATE: I mocked this and don't think the use of the oApp property as the monitor would be a problem. But what is critical is the need to *recheck* the conditional value (in this case oApp.lInitialize) once the lock is obtained.

I think this is what I have right now. I can ajdust a little bit as mentioned to see if it would be better by adding another oApp.lInitialize before the lock.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform