Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Design issue with NameObjectCollectionBase
Message
De
27/09/2010 13:49:09
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Design issue with NameObjectCollectionBase
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01482903
Message ID:
01482903
Vues:
128
Lets say I have this class which uses NameObjectCollectionBase:
    ' Table class
    Public Class Table
        Private cName As String = ""

        Public Sub New(ByVal tcName As String)
            cName = tcName
        End Sub

        Public ReadOnly Property Name As String
            Get
                Return cName
            End Get
        End Property

    End Class

    Public Class Tables
        Inherits System.Collections.Specialized.NameObjectCollectionBase

        Public Overloads Sub Add(ByVal Table As Table)
            BaseAdd(Table.Name, Table)
        End Sub

        Default Public Overloads ReadOnly Property Item(ByVal Title As String) As Table
            Get
                Return CType(BaseGet(Title), Table)
            End Get
        End Property

    End Class
So, I can then reference it like:
oApp.Tables("Member").Name
The definition is done when the application initializes. So, once the application starts, Tables will be initialized and can be accessed during the application. The problem is from the Web. The main class on a Web project is oProcess and not oApp. So, oApp becomes available as oProcess.oApp in such circumstances. So, on the first hit, when ASP.NET reloads the DLL, or on recycle, I can have two simultaneous hits which would want to initialize this. Basically, I have a oProcess.oApp.lInitialize property. Once it is set, the startup initialization won't fire again. But, when oProcess.oApp.lInitialize is False, if I can two simulatenous hits at first, they will see that the application initialization is not done and they will try to do it at the same time.

So far, this was not causing any problem because, when such a situation was happening, one was overwriting the other. The initialization process for the Web was ok because it was mostly a setup of properties or an initialization of a DataRow which was only one record and done from one command.

But, in this case, the situation is different. In order to setup Tables, multiple calls are initialized. It is done like this:
                ' Select all the tables
                If Not loDataProvider.SQLExec("SELECT Table.* " + _
                 "FROM Table") Then
                    Exit Function
                End If

                ' For each table
                For lnCounter = 0 To loDataProvider.nCount - 1
                    loRow = loDataProvider.oDataSet.Tables("Temp").Rows(lnCounter)

                    loTable = New Table(loRow, oApp)
                    oApp.Tables.Add(loTable)
                Next
So, if I have 76 tables, the For/Next will be done 76 times to initialize Tables. So, during that phase, if two hits are simultaneous when the application starts, this can create a mess. So, I need to find a way to initialize into something private and only initialize oApp.Tables at the end such as:
oApp.Tables=Tables2
So, the goal is to make sure that the initialization of oApp.Tables is done private, by the use of a separate container, and only assign it in one shot at the end from one command. However, I am not sure how to do it. Because, this kind of container has to be declared Public.

Any idea?
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform