Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More on cloning
Message
De
16/04/2013 22:52:56
 
 
À
16/04/2013 16:04:31
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:
01571111
Message ID:
01571169
Vues:
36
Ok, here is my report so far on the required changes.

First, based on my analysis of the two errors I got in production, they occured right in the middle of the process. The oProcess.oApp object was available and suddenly not, because the next hit had to reload the oProcess.oApp object. It is a NameObjectCollectionBase that I clear such as oProcess.oApp.Tables.Clear(). So, yes, when doing this, this takes about 1.3 seconds to reload everything back in memory, thus in oProcess.oApp. So, this explains what you said and what I analyzed such as the fact that this is a shallow copy and the objects tied to it are not a copy but a reference to the same address.

So, I made this adjustment:
            'oProcess.oApp = App.oApp.Clone()
            oProcess.oApp = DeepCopy(App.oApp)
So, instead of cloning, I went for a deep copy. The method is like this:
        ''' <summary>
        ''' Using generics will solve some performance issues
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="item"></param>
        ''' <returns></returns>
        Public Function DeepCopy(Of T)(item As T) As T
            Dim formatter As New BinaryFormatter()
            Dim stream As New MemoryStream()
            formatter.Serialize(stream, item)
            stream.Seek(0, SeekOrigin.Begin)
            Dim result As T = DirectCast(formatter.Deserialize(stream), T)
            stream.Close()
            Return result
        End Function
I also had to adjust the App class such as:
    <Serializable> _
    Public Class App

        Public oAdmin As Admin = New Admin()
        Public Countries As New Countries
        Public Messages As New Messages
        Public Provinces As New Provinces
        Public Tables As New Tables

        Public Shared oApp As Framework.App = New Framework.App()

    End Class

    ' Admin class
    <Serializable> _
    Public Class Admin

        <NonSerialized>
        Public oRow As DataRow

    End Class

    <Serializable> _
    Public Class Tables

    End Class

    <Serializable> _
    Public Class Messages

    End Class

    <Serializable> _
    Public Class Provinces

    End Class

    <Serializable> _
    Public Class Countries

    End Class
So, everything that had to be defined as Serializable in the App class has been adjusted. I had to assign a public property in the Admin class as NonSerialized.

When I comment the clone line and activate the DeepCopy() line, I have this error:

"The constructor to deserialize an object of type 'Framework.Framework.Countries' was not found."

So, this is where I am a little bit confused. The DeepCopy() method I grabbed from the net did not mention anything about deserializing anything. So, I believe I am almost done at having it working. Do you know what has to be done to avoid that error or to add the deserializing support to satisfy this infrastucture?
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform