473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Public Shared Property in a DLL

Suppose there is a ASP dot.net web application and a dot.net class library
(written with vb dot.net). The web application references the class library.
The class library contains a ...

Public Class test
Public Shared Property() As String
...
End Property
End Class

Of course, the web application is used by many user in parallel. Now, will
the above property exists once for each user, or will it exist only once for
all users?

Michael G. Schneider
Nov 8 '07 #1
12 1707
All users will see the same property value.

"Michael G. Schneider" <mg*@newsgroups.nospamwrote in message
news:e4**************@TK2MSFTNGP03.phx.gbl...
Suppose there is a ASP dot.net web application and a dot.net class library
(written with vb dot.net). The web application references the class
library. The class library contains a ...

Public Class test
Public Shared Property() As String
...
End Property
End Class

Of course, the web application is used by many user in parallel. Now, will
the above property exists once for each user, or will it exist only once
for all users?

Michael G. Schneider


Nov 8 '07 #2
"Aidy" <ai**@xxnoemailxx.comschrieb im Newsbeitrag
news:_8******************************@bt.com...
All users will see the same property value.
Thanks a lot for the very fast response.

Is it possible to have a "global variable" in the DLL, which exists
per-user?

Michael G. Schneider
Nov 8 '07 #3
If you want something per-user then use the Session object.

"Michael G. Schneider" <mg*@newsgroups.nospamwrote in message
news:ew**************@TK2MSFTNGP02.phx.gbl...
"Aidy" <ai**@xxnoemailxx.comschrieb im Newsbeitrag
news:_8******************************@bt.com...
>All users will see the same property value.

Thanks a lot for the very fast response.

Is it possible to have a "global variable" in the DLL, which exists
per-user?

Michael G. Schneider


Nov 8 '07 #4
A session variable is your closest match.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Michael G. Schneider" <mg*@newsgroups.nospamwrote in message
news:ew**************@TK2MSFTNGP02.phx.gbl...
"Aidy" <ai**@xxnoemailxx.comschrieb im Newsbeitrag
news:_8******************************@bt.com...
>All users will see the same property value.

Thanks a lot for the very fast response.

Is it possible to have a "global variable" in the DLL, which exists
per-user?

Michael G. Schneider

Nov 8 '07 #5
"Aidy" <ai**@xxnoemailxx.comschrieb im Newsbeitrag
news:j4******************************@bt.com...
If you want something per-user then use the Session object.
Thanks a lot for the answer.

With Session you suggest the HttpSessionState object. Correct? How can I use
that object in the DLL? And is it ok to use it inside the DLL? Maybe the DLL
is not used from within an ASP application. Maybe it is used from within an
EXE.

What I want to have, is the following. There is a DLL. It will be used from
within an ASP dot.net application, and also from an EXE program. The DLL
needs some global data (for example some configuration data that is read
from an XML file on startup). I want this global data to be read once, then
used several times as long as the DLL is active. In case of the web
application, the global data may not be shared among the users.

Michael G. Schneider
Nov 8 '07 #6
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschrie b im
Newsbeitrag news:%2******************@TK2MSFTNGP02.phx.gbl...
>A session variable is your closest match.
Also many thanks for your answer. There is a longer response in the other
part of this thread.

Michael G. Schneider
Nov 8 '07 #7
You could desing ariound thios. For example in a stand alone app you have
only a single user. In aweb app you'll need to know whih user is calling
your app so that you can get the correspoing confi (bascially it could be a
collection).

Hard to tell but another way is to avoid this. What is this DLL supposed to
do. It could just do what you need to and have paramters provided by the
external world allowing to sotre them as you which rather than having the
DLL directly accessing those pamreatmers..

Hard to say more as we don"t know what it is about...

Good luck

--
Patrice

"Michael G. Schneider" <mg*@newsgroups.nospama écrit dans le message de
news: OV**************@TK2MSFTNGP02.phx.gbl...
"Aidy" <ai**@xxnoemailxx.comschrieb im Newsbeitrag
news:j4******************************@bt.com...
>If you want something per-user then use the Session object.

Thanks a lot for the answer.

With Session you suggest the HttpSessionState object. Correct? How can I
use that object in the DLL? And is it ok to use it inside the DLL? Maybe
the DLL is not used from within an ASP application. Maybe it is used from
within an EXE.

What I want to have, is the following. There is a DLL. It will be used
from within an ASP dot.net application, and also from an EXE program. The
DLL needs some global data (for example some configuration data that is
read from an XML file on startup). I want this global data to be read
once, then used several times as long as the DLL is active. In case of the
web application, the global data may not be shared among the users.

Michael G. Schneider

Nov 8 '07 #8
"Patrice" <http://www.chez.com/scribe/schrieb im Newsbeitrag
news:ej**************@TK2MSFTNGP03.phx.gbl...
Hard to say more as we don"t know what it is about...
Thanks a lot for the answer. I can give you some more information. Maybe the
task is clearer then.

The DLL offers some classes. Each of these classes offers several methods.
Each of these methods needs basic data. Maybe it is data that is read from a
database or from a configuration XML file.

I do not want to read the basic data on each an every method call. The DLL
should read the data once and store it internally.

This might be solved by an extra method, which reads the basic data, stores
it in some objects, and returns it to the caller. The caller would then hand
over this data to each of the method calls. Something like

Dim oBaseData As DLL.BaseData
Dim oWorker As DLL.Worker
oWorker = New DLL.Worker
oBaseData = oWorker.ReadBaseData("server", "database")
oWorker.Calc1(oBaseData, ...)
oWorker.Calc2(oBaseData, ...)
oWorker.Calc3(oBaseData, ...)

So the oBaseData would be passed into the DLL, and then also from one
function to the next function within the DLL.

This is not so nice. Many parameters have to be passed along.

As this is really "global data", I prefered to have a "global variable" and
access that it from each DLL function.

Michael G. Schneider
Nov 8 '07 #9
Hi Michael,

Based on my understanding, you need to make your class library used by both
your web application and windows application and you need to make sure some
classes could use per-user settings/data.

I think you could add reference to System.Web to your class library and use
HttpContext.Current to determine if it's used by a web application or
windows application. If it's web application (having a non-null
HttpContext.Current), then use the session; otherwise, use a global object
such as Hashtable.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 9 '07 #10
""Walter Wang [MSFT]"" <wa****@online.microsoft.comschrieb im Newsbeitrag
news:0p*************@TK2MSFTNGHUB02.phx.gbl...
I think you could add reference to System.Web to your class library and
use
HttpContext.Current to determine if it's used by a web application or
windows application. If it's web application (having a non-null
HttpContext.Current), then use the session; otherwise, use a global object
such as Hashtable.
Hello Walter,

thanks a lot for the answer. This does work.

I thought that in a non-web application I was not allowed to reference the
web parts of dot.net. However, it does work. So you can code references to
objects such as HttpContext.Current - you only have to take care of the fact
that these references might be Nothing.

Michael G. Schneider
Nov 9 '07 #11
Another option would be to insulate the DLL form the underlying settings
storage using a "provider" scheme.

--
Patrice

""Walter Wang [MSFT]"" <wa****@online.microsoft.coma écrit dans le message
de news: 0p*************@TK2MSFTNGHUB02.phx.gbl...
Hi Michael,

Based on my understanding, you need to make your class library used by
both
your web application and windows application and you need to make sure
some
classes could use per-user settings/data.

I think you could add reference to System.Web to your class library and
use
HttpContext.Current to determine if it's used by a web application or
windows application. If it's web application (having a non-null
HttpContext.Current), then use the session; otherwise, use a global object
such as Hashtable.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 9 '07 #12
Hi Michael,

Adding reference to System.Web in your class library should be ok. Also,
the System.web assembly is included in default .NET Framework
redistribution therefore you don't need to worry if your class library is
used by a windows application.

Following KB also demonstrates such usage when you need to output trace
message to a web application from a class library.

#HOW TO: Get Trace.Write Statements in Regular Code to Appear in Page Logs
by Using Visual C# .NET
http://support.microsoft.com/kb/327848
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 12 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1798
by: Joe Fallon | last post by:
I have a Shared varibale in a base class and all the Shared methods in the sub-classes use it (and CHANGE it). I thought I was saving myself the "trouble" of Dimming this variable inside each...
10
3660
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
13
3596
by: MJ | last post by:
as topic, if i wan to create an array where the content of the array can be edited by form1 and form2, how i going to do it? for example the content of array is {1,2,3} form2 change the content...
4
45073
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the...
9
8855
by: Stefan De Schepper | last post by:
Should I use: Private m_Name As String Public Property Name() As String Get Return m_Name End Get Set(ByVal Value As String) m_Name = Value
27
2674
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
2
2217
by: Jon Paal | last post by:
In a 2.0 vb code class, I have a private property and a shared public function The property value has already been passed into the class, now I am trying to use a public finction which also needs...
8
1999
by: Al | last post by:
I'd like to create Class Library in VB 2005, which has a property accessible by external programs. I decided to include 1 Class with 1 property in this project. I placed this code in Class:...
3
2243
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.