Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using SyncLock
Message
De
24/01/2011 12:06:19
 
 
À
24/01/2011 11:58:33
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:
01497206
Vues:
49
>This looks like the 'super-safe' C# implementation:
public sealed class Singleton
>{
>   private static volatile Singleton instance;
>   private static object syncRoot = new Object();
>
>   private Singleton() {}
>
>   public static Singleton Instance
>   {
>      get 
>      {
>         if (instance == null) 
>         {
>            lock (syncRoot) 
>            {
>               if (instance == null) 
>                  instance = new Singleton();
>            }
>         }
>
>         return instance;
>      }
>   }
>}
(from http://msdn.microsoft.com/en-us/library/ff650316.aspx). Only problem is that VB doesn't have 'volatile' :-{


This "volatile" keyword is a new one for me (been around awhile, but I guess I hadn't heard of it). The link you provided to MSDN states that if your member is declared using the volatile keyword, then you don't have to use a lock ... so, if that's the case, then I'm confused why you did ... guess I should probably read up on it more at some point.

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform