473,382 Members | 1,635 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,382 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 1520
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.