473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1521
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*******@discussions.microsoft.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*******@discussions.microsoft.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*******@discussions.microsoft.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
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...
10
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...
7
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...
14
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...
33
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...
5
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...
2
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...
15
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...
0
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...

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.