473,769 Members | 6,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shared methods (MSDAAB)

tom
Hello,

I'm using the ms data access application blocks.
My question is about the fact that everywhere shared
methods are used.

Does this mean that when more than 1 user at the same
time executes the same function they can interfere with
one another as these functions are the same for all
instances of the class (and thus internal variables
also?)?

I'll explain with a simple example :
user 1 and user 2 both want to call function A that
returns a dataset based on a provided sql statement.

1. user 1 calls function A
2. function A does some internal processing (and has not
yet reached the point where it gets the dataset) and sets
internal variable to hold sql statement
3. user 2 calls function A with different sql statement
4. internal variable for sql statement of user 2 gets set
5. function reaches the point for user 1 where it
executes the return of the dataset --> Will it use the
sql statement of user 1 or that of user 2 ??
....

I hope you understand what I'm trying to explain and
hopefully you can also explain to me if this scenario is
possible or not?

thanx,
t
Nov 22 '05 #1
3 1552
In that case you are dealing with re-entrance, which you should try to
avoid! In VB.NET you can use the SyncLock statement (Allows statements to be
synchronized on a single expression.) for helping you out:
http://msdn.microsoft.com/library/de...tmSyncLock.asp
The SyncLock statement ensures that multiple threads do not execute the same
statements at the same time. When the thread reaches the SyncLock block, it
evaluates the expression and maintains this exclusivity until it has a lock
on the object that is returned by the expression. This prevents an
expression from changing values during the running of several threads, which
can give unexpected results from your code.

Note The type of the expression in a SyncLock statement must be a
reference type, such as a class, a module, an interface, array or delegate.
Example
Class Cache
Private Shared Sub Add(ByVal x As Object)
SyncLock GetType(Cache)
End SyncLock
End Sub

Private Shared Sub Remove(ByVal x As Object)
SyncLock GetType(Cache)
End SyncLock
End Sub
End Class
--
Greetz,
Jan
_______________ _______________ ____
Read my weblog: http://weblogs.asp.net/jan
"tom" <an*******@disc ussions.microso ft.com> schreef in bericht
news:00******** *************** *****@phx.gbl.. .
Hello,

I'm using the ms data access application blocks.
My question is about the fact that everywhere shared
methods are used.

Does this mean that when more than 1 user at the same
time executes the same function they can interfere with
one another as these functions are the same for all
instances of the class (and thus internal variables
also?)?

I'll explain with a simple example :
user 1 and user 2 both want to call function A that
returns a dataset based on a provided sql statement.

1. user 1 calls function A
2. function A does some internal processing (and has not
yet reached the point where it gets the dataset) and sets
internal variable to hold sql statement
3. user 2 calls function A with different sql statement
4. internal variable for sql statement of user 2 gets set
5. function reaches the point for user 1 where it
executes the return of the dataset --> Will it use the
sql statement of user 1 or that of user 2 ??
...

I hope you understand what I'm trying to explain and
hopefully you can also explain to me if this scenario is
possible or not?

thanx,
t

Nov 22 '05 #2
Tom,

As Jan mentioned, re-entrance can be a bad thing if more than one thread
changes a variable that is shared between threads.
4. internal variable for sql statement of user 2 gets set
By internal, do you mean local to the function or local to the class
(shared)?

If you mean local to the function, you should be fine. Each time a function
(shared or not) is called, all its local variables get pushed on to the
current thread's stack - two threads calling the same function should not be
able to interfere with each other because they each get their own copy of
the variables.

However, if the variables are stored at the class level, you should use the
synclock statement to make sure only one thread can access a variable at a
time.

Hope this helps,

Trev.
"tom" <an*******@disc ussions.microso ft.com> wrote in message
news:00******** *************** *****@phx.gbl.. . Hello,

I'm using the ms data access application blocks.
My question is about the fact that everywhere shared
methods are used.

Does this mean that when more than 1 user at the same
time executes the same function they can interfere with
one another as these functions are the same for all
instances of the class (and thus internal variables
also?)?

I'll explain with a simple example :
user 1 and user 2 both want to call function A that
returns a dataset based on a provided sql statement.

1. user 1 calls function A
2. function A does some internal processing (and has not
yet reached the point where it gets the dataset) and sets
internal variable to hold sql statement
3. user 2 calls function A with different sql statement
4. internal variable for sql statement of user 2 gets set
5. function reaches the point for user 1 where it
executes the return of the dataset --> Will it use the
sql statement of user 1 or that of user 2 ??
...

I hope you understand what I'm trying to explain and
hopefully you can also explain to me if this scenario is
possible or not?

thanx,
t

Nov 22 '05 #3
tom
Thanx Trev,

You're comment helped a lot.

By internal I indeed meant local to the function.
I just was not sure if these local variables could be
overwritten when using shared methods as I thought that
only one instance of the function was stored.

t

-----Original Message-----
Tom,

As Jan mentioned, re-entrance can be a bad thing if more than one threadchanges a variable that is shared between threads.
4. internal variable for sql statement of user 2 gets set

By internal, do you mean local to the function or local to the class(shared)?

If you mean local to the function, you should be fine. Each time a function(shared or not) is called, all its local variables get pushed on to thecurrent thread's stack - two threads calling the same function should not beable to interfere with each other because they each get their own copy ofthe variables.

However, if the variables are stored at the class level, you should use thesynclock statement to make sure only one thread can access a variable at atime.

Hope this helps,

Trev.
"tom" <an*******@disc ussions.microso ft.com> wrote in messagenews:00******* *************** ******@phx.gbl. ..
Hello,

I'm using the ms data access application blocks.
My question is about the fact that everywhere shared
methods are used.

Does this mean that when more than 1 user at the same
time executes the same function they can interfere with
one another as these functions are the same for all
instances of the class (and thus internal variables
also?)?

I'll explain with a simple example :
user 1 and user 2 both want to call function A that
returns a dataset based on a provided sql statement.

1. user 1 calls function A
2. function A does some internal processing (and has

not yet reached the point where it gets the dataset) and sets internal variable to hold sql statement
3. user 2 calls function A with different sql statement
4. internal variable for sql statement of user 2 gets set 5. function reaches the point for user 1 where it
executes the return of the dataset --> Will it use the
sql statement of user 1 or that of user 2 ??
...

I hope you understand what I'm trying to explain and
hopefully you can also explain to me if this scenario is possible or not?

thanx,
t

.

Nov 22 '05 #4

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

Similar topics

3
314
by: tom | last post by:
Hello, I'm using the ms data access application blocks. My question is about the fact that everywhere shared methods are used. Does this mean that when more than 1 user at the same time executes the same function they can interfere with one another as these functions are the same for all instances of the class (and thus internal variables
10
3569
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
7
1641
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What are the implications, (in terms of memory, application footprint, resource use, threading, and so forth), of using Shared methods? These Shared classes raise some interesting questions. For example... (1). If I have a custom utility class where I keep all of my Shared methods
14
6312
by: Joe Fallon | last post by:
I am trying to build a Data Access Layer for a SQL Server back end. My class has a number of methods in it. The constructor takes a connection string. I currently have to instantiate an object in order to use one of my methods. So I end up doing this quite a lot in my app. If I change all of the methods to be Shared does that mean I can just use them without instantiaing an instance of my DAL class?
33
3494
by: Joe Fallon | last post by:
1. I have a Base class that has a certain amount of functionality. 2. Then I have a CodeSmith generated class that inherits from the Base class and adds functionality. 3. Since I want to be able to re-generate the classes on level 2 I have a 3rd level that inherits from them and implements specific hand coded methods. 4. My colleague asked me to create a 4th level class that inherits the 3rd level class so he can write custom...
5
11607
by: Erik Cruz | last post by:
Hello! I have read some threads discussing the fact that a module is in reality a shared class. If I try to create a Public Shared Class in vb.net I receive a compile error. Why? If I can't explicitly create a shared class, how does vb.net creates it? TIA, Erik Cruz
2
2635
by: Elephant | last post by:
Hello, question, I want to make a COM-compatible .NET DLL (Visual Basic). For this I need an interface. The DLL has a class that must contain methods that can be used without making an instance of the class first. So I have a class that has methods that derrive from an interface, and the same class has methods that are Shared....but methods that are derrived from an interface are not allowed to be Shared...
15
2784
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.' So, does this mean All the static/shared methods written in .NET compatible programming language, such as C#, VB.NET, are guaranteed to be...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.