|
Nope. It might help to think of shared fields/methods etc as existing in a separate class that is by default a singleton.
Shared fields exist on this singleton object that is created once and only once per appdomain (an appdomain is a subsection of a process - can be considered synonymous with process for most situations). This singleton object is referenced via the class name i.e. Class1.fieldY or Class1.methodX() and is available anywhere in the appdomain, accessors (public, friend etc) permitting.
Any values set will persist until the appdomain is unloaded. In this case myVal will continue to increase with every call to GetInstance() until IIS is restarted.
You can create and destroy as many Class1 instances as you wish, it will have no bearing on the shared fields defined in Class1.
To determine if the current instance of Class1 is the same as the last, call cls1.GetHashCode() where cls1 is an instance of Class1. If the values are different then you have different instances.
------------------------------------------------
I'm largely language agnostic -
After a while they all bug me
------------------------------------------------
|
|
|
|
|
Thanks for explaining that, MidwestLimey. I was not aware that those shared variables were independent of the class instance.
|
|
|
|
|
When you call GetInstance, you are getting a copy of the reference to the object. Clearing that copy does not clear the reference stored in the Shared variable.
What are you trying to accomplish, really? Shared variables are rarely useful in web applications.
---
single minded; short sighted; long gone;
|
|
|
|
|
Actually, I wasn't really trying to use the shared variable among the various web applications. Such variables are indeed quite useful, but for that, I would usually just use an Application variable. I was just using it here to see if my object was being destroyed or not. As it turns out, it wasn't the right way to figure that out.
What I was trying to do was gain a deeper understanding of the use of singleton objects in web applications.
|
|
|
|
|
Can ListItem be used in vb.net 2005?
When I use the code:
For Each item As ListItem in listbox2.Items<br />
If item.Value = fi.Name Then<br />
fFound = True<br />
End If
I will tell me to change ListItem to ListViewItem. When I change it I get the error:
Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ListViewItem'.
Any suggestions?
jds1207
|
|
|
|
|
ListItem is a class in System.Web.UI.WebControls , it looks like your trying to use that in a windows form application.
jds1207 wrote: will tell me to change ListItem to ListViewItem. When I change it I get the error:
Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ListViewItem
That will not work, you cant use a ListViewItem for a listBox
The ListBox.Items is an Object collection
For Each item As Object In listBox2.Items
If Convert.ToString(item) = fi.Name Then
fFound = True
End If
Next
|
|
|
|
|
i am trying to make an oledb connection with a password protected Access databaase.I tried the vizard on vb.net.but i got a connection error as " Cant start ur application because either Work group information file is missing or it is opened exclusievly by one another.please help me
|
|
|
|
|
Hi,
an example to connect to an Access database:
Dim sql As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _<br />
"Data Source=c:\resource.mdb;Jet OLEDB:System database=\\system.mdw;User Id=; Password=;"<br />
<br />
Using connection As New OleDb.OleDbConnection(sql)<br />
<br />
connection.ConnectionString = sql<br />
connection.Open()
System database is the path where you have Work group information and Data Source is the path where is your database.
Hope this help.
regards.
-- modified at 2:26 Wednesday 13th June, 2007
|
|
|
|
|
in my computer i use 2 ip address
i create a comuniction application using UDP and connect to server ( send and recive working good)
and now i whand to send data from the second ip address
how i can config to UdpClient to use the first ip or the second ?
Thanks
|
|
|
|
|
to send -
you can either randomize
you can use sequential - 1 then 2 then 1 then 2 etc
you can look at the PC's ip and if the last number is odd, use 1 else use 2
to receive -
you need to setup 2 listeners to handle both IPs
|
|
|
|
|
how i can select the localIp address
i use the UDPClient and i dont see where to insert my local ip
i need to send data from the first IPAddress and then send data from the second ipaddress
both send to the same ipaddress
|
|
|
|
|
Hi,
I'm using VB.NET 1.1.
I have a SqlDataReader varible that calls a function that has a return type of SqlDataReader like:
Dim dr As SqlDataReader = Me.GetProductsDataReader()
The function GetProductsDataReader() doesn't close the SqlDataReader any where, but then when I try to do (after the call):
While dr.Read()
' code here
End While
..then I get the following erro:
Invalid attempt to Read when reader is closed.
Please can some one help me?
Regards
ma se
|
|
|
|
|
Could you show your code in GetProductsDataReader() ?
|
|
|
|
|
Hi,
better you use
dim cmd1 As SqlCommand = conn.CreateCommand()<br />
Dim drd1 As SqlDataReader = cmd1.ExecuteReader()<br />
while drd1.read()<br />
..<br />
end while<br />
hope this would help.
regards
|
|
|
|
|
hi,
Did you closed the datareader before in your prog ???
please post your code of GetProductsDataReader()
regards,
koolprasad2003
If the message is useful for U then please Rate This message...
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
I'm using VS 2005 with SP1. I created a user control. In the same solution I created a new project to test the control. In the test project, I added a reference to the user control project. My user control does not show up in the toolbox. What do I have to do to have it show up?
Thanks,
VF
|
|
|
|
|
add it manually - right-click on toolbox and click add and choose your dll...
|
|
|
|
|
There isn't an "Add" when I right-click on the toolbox.
However, I used the "Add tab", and entered an appropriate name. Then I dragged my dll file into the area in the new tab. Now it shows up.
|
|
|
|
|
sorry went by memory -- see what that got me...
it's actually "choose item" will allow you to add to the toolbox.
|
|
|
|
|
"Choose Items..." and browsing to the dll also works.
Next question: How do I modify the icon for the user control that is displayed in the toolbox. I looked for an Icon property for my user control, but there doesn't seem to be one.
|
|
|
|
|
You don't have to add it manually. This SHOULD show up automatically when you build the project. But, it's been known to screw up. Sometimes closing Visual Studio and restarting it, loading your project and recompiling takes care of it. Other times, you have to right-click the Toolbox and pick Reset Toolbox.
|
|
|
|
|
Still doesn't work. At least I can add it manually.
Do you know how I can modify the icon that shows up in the toolbox? Doesn't seem to be an Icon property for the user control.
|
|
|
|
|
You can't. The icon in the ToolBox doesn't show up properly at all during development. It won't show a proper icon until the control is finalized in a Release build and is registered in the GAC, complete with strong name.
|
|
|
|
|
Hi,
I'm using VB2005 Express to create a small app which is intended to allow me to build up the contents of an XML file.
I've got the DataGridView in place, and it is reading in and displaying the contents of an XML file.
I've got a button on the form which allows me to insert a column in the DataGridView, but when I press 'Save' it writes an XML file, but it doesn't include the new column I've just entered in my grid.
I suspect that it may be a binding problem, but I don't know how to code this part of the app.
Any advice would be appreciated.
|
|
|
|
|
You can try this :
'=====Read and display xml file on DataGridView=====
Dim ds as new DataSet
ds.ReadXml("c:\YourFile.xml")
dgv.DataSource = ds.Tables(0)
'=====End=====
'=====Create new column=====
Dim col as new DataColumn("MyNewColumn",System.Type.GetType("System.String"))
ds.Tables(0).Columns.Add(col)
'=====End=====
'=====Save xml file
ds.WriteXml("c:\\YourFile.xml")
'=====End=====
|
|
|
|