Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using SyncLock
Message
De
15/01/2011 05:28:27
 
 
À
14/01/2011 10:15:52
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01496120
Message ID:
01496273
Vues:
69
>>Where does lFirstHit get set to False ?
>
>In EndRequest(), which is executed at the end:
>
>
>        ' Execute at the end of each hit
>        Public Function EndRequest() As Boolean
>
>            ' If this is the first hit
>            If lFirstHit Then
>                lFirstHit = False
>            End If
>
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform