Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling first hit on a site
Message
De
27/09/2010 15:05:45
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
27/09/2010 14:55:02
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01482914
Message ID:
01482916
Vues:
48
>I have adjusted the code which handles the first hit on a site. I had to make a locking adjustment because one of the process was a group type approach so I had to make sure that only one would go in there. Basically, it goes like this when the application starts for a Web site or when it is being recycled:
>
>
>            ' If this is the first hit
>            If lFirstHit Then
>
>                ' Make sure to lock the thread otherwise, it two simultaneous hits are entering
>                ' here, which could be the case when the application starts, you could end up in a real mess
>                SyncLock loObjectLock
>
>                    ' If the application initialized has been completed by someone else, then, we can skip that part. The scenario here
>                    ' is that the first one who get into there will do the setup. But, we need to avoid the other
>                    ' one to setup again.
>                    If Not oApp.lInitializeWeb Then
>
>                        ' Do initialization here
>
>                        oApp.lInitializeWeb = True
>                    End If
>
>                End SyncLock
>
>            End If
>
>
>Based on my tests, this seems to have resolved the issue. So, while oApp.IInitializeWeb is not set to True, it might well be possible two users are accessing the Web site at first. So, I have added a property at the application level to tell the hit that the Web initialization has been done. So, the first one gets in and lock the thread. When the thread is unlocked, the next one will go in but will skip it as the oApp.lInitializeWeb property has been set.
>
>lFirstHit controls the first hit on the site. So, lFirstHit turns True once this is done so the logic of a hit will never go in this code for as long as the application runs after.
>
>I would just like to verify if someone could see something wrong in there.

I'm handling it using this code:
public static class Bootstrapper
    {
        private static readonly object _lock = new object();
        private static bool _initialized;

        public static void Bootstrap()
        {
            if (!_initialized)
            {
                lock (_lock)
                {
                    if (!_initialized)
                    {
                        _initialized = true;

                        StructureMapConfiguration.Initialize();

                        var startupTasks = ObjectFactory.GetAllInstances<IStartupTask>();

                        startupTasks.Each(task => task.Execute());
                    }
                }
            }
        }
    }
I call this in my Application_Start event in the global.asax file. Looks like we had the same concern, but I'm handling it a bit differently by checking the _initialized variable before and after the lock.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform