louis wrote:
Can someone please discuss "Synclock" or other methods to use for making a
class 'thread safe". I need to have about 4 processes running (probably on
backgroundworker threads) and all will need to call the same class for
reading data (not SQL Server).
Synclock is a keyword that provides simple access to the Monitor class.
Monitor allows you to ensure that only one Thread is running a given
piev of code at any given time.
If each worker thread creates an "instance" of the class,
won't that be good enough?
Strictly speaking, no.
You ought to have synchronisation logic on "sensitive" methods so that
only one Thread can be executing it at any time. Without this, you can
get updates interlacing with one another, causing a hell of mess.
However, since you are "wrapping up" a /database/ it may not be so much
of an issue; you could probably manage the synchronisation just as
easily at the database level.
HTH,
Phill W.