P
Paul
Hi.
Just trying to find out the best approach as I beleive it might give me
problems later on down the road.
I have an ASP.NET application which references a shared database class which
contains methods for serialising and de-serialising objects to the database
storage. I put this as a shared class as multiple web clients will be using
the class to store and retreive data, the problem I'm haivng now is that I
think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name and
then some funcitons which execute requests against the table name, however
client A could be looking at table1 and client B will be looking at table2.
Now would the best approach be to use a SyncLock on the class before I run
the setting of the varibles and functions or get each client to initiate the
class with a Dim myClass as New MyClass ? What would be the best approach,
bering in mind that one clients requests may take a little while and the
Synclock would lock the class until this has completed and at this point we
may have 100 - 200 requests ???
An example being..............
Public MyClass
private shared TableName as string
public shared function SetTableName(s as String)
TableName = s
end function
public shared function DoSomething
Dim SQLString = "SELECT * from " + TableName
end function
End Class
Would I just use
SyncLock GetType(MyClass)
MyClass.SetTableName = "Table1"
MyClass.DoSomething
End Synclokc
or
Dim mc as New MyClass
MyClass.SetTableName = "Table1"
MyClass.DoSomething
Thanks in advance.
Just trying to find out the best approach as I beleive it might give me
problems later on down the road.
I have an ASP.NET application which references a shared database class which
contains methods for serialising and de-serialising objects to the database
storage. I put this as a shared class as multiple web clients will be using
the class to store and retreive data, the problem I'm haivng now is that I
think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name and
then some funcitons which execute requests against the table name, however
client A could be looking at table1 and client B will be looking at table2.
Now would the best approach be to use a SyncLock on the class before I run
the setting of the varibles and functions or get each client to initiate the
class with a Dim myClass as New MyClass ? What would be the best approach,
bering in mind that one clients requests may take a little while and the
Synclock would lock the class until this has completed and at this point we
may have 100 - 200 requests ???
An example being..............
Public MyClass
private shared TableName as string
public shared function SetTableName(s as String)
TableName = s
end function
public shared function DoSomething
Dim SQLString = "SELECT * from " + TableName
end function
End Class
Would I just use
SyncLock GetType(MyClass)
MyClass.SetTableName = "Table1"
MyClass.DoSomething
End Synclokc
or
Dim mc as New MyClass
MyClass.SetTableName = "Table1"
MyClass.DoSomething
Thanks in advance.