Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Web Application and Class Library Instances

$
0
0

Hi there, I have a small problem that I'm hoping some clever clogs can help me with. I have a class library and a web application. The web application sets up an instance of the class library and stores it in a session variable called localSession, this works really well on the web side. However, when two users access the same page the second of the two class library instances becomes dominant and all New object calls go through this instance. The trouble is the instances are loaded with the data for just that person and a little field I like to keep with the last updater keeps defaulting to the second user (the same thing happens with the collection handling but that's of lesser concern). Incidentally the class library instance refers to itself as myCurrentSession which I set in the constructor for the controlling class, the variable is held as a global in a module within the class library. Is there a more cute way to maintain separate instancing? Thanks, Davy

To add some context:

The code in the Application Start event is:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when a new session is started
    Dim user As New TimeData.TimeCardData
    Session.Add("localSession", user)
    Session.Add("selDate", 0)
    user.RunMode = "Web"

End Sub

Referring to CType(Session("localSession"),TimeData.TimeCardData) returns the appropriate object - I ran watches with two browser instances, in each case of a referral from the web form I got the correct object. However, when I instance a class directly from a web form (Dim tr as New TimeData.TimeCardRecord) it is always the second instance that creates the TimeCardRecord object. I even tried adding an instance creation method within the controlling class and even though it was the correct master object doing the calling the TimeCardRecord item created was still instanced by the second web instance.

The master class is not Shared - I made that mistake previously!

 


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>