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