Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
Previous Previous
 
Next Next
New Post 1/23/2010 1:01 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi Derek,

Declaring the property as you suggest, and you are on the right track, so the answer to that question is yes.

I am not sure if I understand your point here regarding the second question. You can create a class library where you have a class with the shared property as in your code above. That class library can be created in a seperate project and function as your Visual WebGui utility library. In there you declare a class with your shared property as in your message.

When you use it, you just have to reference that new utility class library in your projects and then you can reference UtilityNamespace.UtilityClass.CustomObjectName = "x" without creating an instance of the class.

Does that answer your question ?

If not, please explain.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 3/17/2010 12:06 PM
  purtycool
48 posts
www.tphinc.com
No Ranking


Re: Global Variable question/Clarification 
Modified By purtycool  on 3/17/2010 3:39:26 PM)

Dear All,

To confirm that I understand the discussion, modules in VB.NET are static and variables declared in modules are shared between all sessions of a WebGui application (i.e. all instances of a WebGui application). And because static means global, this implies that a property or variable declared as Public in a module will be allocated one memory slot on the Web Server.
 
For example, a WebGui application has a public (i.e. global) variable declared in a module. When the first session of that WebGui application starts, the Web Server will allocate memory for that global variable. When the next session of that WebGui application starts, it will access the global variable stored in that memory slot. The Web Server will NOT create a second memory slot for global variable. Thus, both WebGui sessions will be accessing the same memory slot or public variable.
 
So if I want to create Constants that are shared across all WebGui sessions, I could create a module as follows:
 
Module modGlobalConstants
 
    'Column States
    Friend Const blnBoundToDataSource As Boolean = True
    Friend Const blnBoundToDataSourceNot As Boolean = False
 
    Friend Const blnFrozen As Boolean = True
    Friend Const blnFrozenNot As Boolean = False
 
    Friend Const blnReadOnly As Boolean = True
    Friend Const blnReadOnlyNot As Boolean = False
 
    Friend Const blnVisible As Boolean = True
    Friend Const blnVisibleNot As Boolean = False
 
End Module
 
Or if want to create a procedure that is shared across all WebGui sessions, I could create a module as follows:
 
Module modGlobalSubs
 
Friend Sub PopulateCountryDGVComboBox( _
ByRef CountryComboBox As Gizmox.WebGUI.Forms.DataGridViewComboBoxColumn _
, ByRef dbConn As SqlConnection _
)
            Dim cmd As New SqlCommand("sp_COUNTRY_Select", dbConn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim dr As SqlDataReader = cmd.ExecuteReader()
 
            With CountryComboBox
                While dr.Read()
                    .Items.Add(dr("COUNTRY_NAME"))
                End While
            End With
 
            dr.Close()
            cmd.Dispose()
End Sub
 
End Module
 
Or, if I want to store the Vendor Name for each session, I want to either store the Vendor Name in a session variable as follows:
 
Context.Session.Item("VendorName") = VendorName
 
Or as an alternative approach, I could create a class called GlobalProperties and use Get and Set to store the value as shown below
 
Public Class clsGlobalProperties
 
    Public Property VendorName() As String
        Get
            Return VWGContext.Current(“VendorName”)
        End Get
        Set(ByVal value As String)
            VWGContext.Current(“VendorName”) = value
        End Set
    End Property
 
End Class
 
Then, I would instantiate the class in each form as illustrated below:
 
Private GP As New clsGlobalProperties
Dim VendorName As String = GP.VendorName
 
However, I would NOT want to store the Vendor Name in a property defined in a module such as shown below because each WebGui session will reference the same memory slot on the Web Server:
 
Module modGlobalProperties
 
    Private _VendorName As String
 
    Public Property VendorName() As String
        Get
            Return _VendorName
        End Get
        Set(ByVal value As String)
            VendorName = value
        End Set
    End Property
 
End Module
 
In other words, each WebGui session does NOT create its own instance of the above module.
 
Have I correctly understood the discussion? If not, please correct me.
 
Thanks!
 
New Post 3/18/2010 11:05 AM
  purtycool
48 posts
www.tphinc.com
No Ranking


Re: Global Variable question/Clarification 

Dear All,

I though I'd post a follow-up. I converted the code modules to classes declared as Friend with their functions, subs, properties declared as Protected Friend. However, instantiating these classes means that more memory will be used on my web server and more burden will be placed upon IIS. So far, I have not experienced sessions being flip-flopped nor data being criss-crossed as reported by some of the people on the forums running IIS. However, it may just have been luck. For the meantime, I'll maintain two versions of my application: one that uses code modules and one that does not use code modules.

Regards!

 
New Post 3/18/2010 3:33 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi,

Generally your understanding is correct.

A few notes.

1) Private or Public module variables - It does not matter if you define your module variable as private or public, they will occupy the same memory slot in all instances of the application. The static behaviour is what matters here, not the scope.

2) Context variables - You probably know already that there is a difference storing values in the Session or in the Context, right ?

Seems to me that you have understood the concept quite fine.

Regarding your second post, then of course there will be more memory consumed by storing your data in instance variables versus static. You are correct about that. As for the criss crossing of data between sessons, I only remember one thread discussing that problem which you can read here. Seems to be an IIS7 bug that will surface in very special cases. I just added a post on that thread to inquire about the status.

For your information, you do not have to use modules in vb.net to get a shared procedure or variable. You can as well use the "shared" keyword to get the same results.

Palli

 

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 3/26/2010 6:01 PM
  purtycool
48 posts
www.tphinc.com
No Ranking


Re: Global Variable question/Clarification 

Dear Palli,

Thank you for the reply and clarification about shared procedures and variables. Also, it looks like am quite mistaken about the extent of "criss crossing of data between sessions in IIS7" reported by people on the forums.

Regards,

Bill

 
Previous Previous
 
Next Next
  Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
Azure banner
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS