Thanks for the response.
This static method is set up to get a single record from a database.
Initially, calls to this method were made serially, so I was not concerned at
all about threading. Now, calls are made concurrently from multiple threads,
so I'm concerned about a subsequent call trashing data in a previous call and
getting data corruption.
I guess I need to put a finer point on what's meant by "shared data." Even
though each call only returns a single record, I'm still returning each
record as a DataTable (not just a row), and the DataTables get merged upon
return.
Any more thoughts are greatly appreciated.
Randy
"Jon Skeet [C# MVP]" wrote:
randy1200 <ra*******@discussions.microsoft.comwrote:
I'm working in Visual Studio 2005.
I have the following method. I'm trying to figure out why I wouldn't want to
wrap the contents in a lock(MyLockObject) {...} Seems to me that having a
static method in a mutlithreaded environment isn't thread safe.
public static MyDataSet Load()
{
//Open database connection
//Load data from database into dataset
//Close connection
}
Any thoughts?
Well, is that method going to use any shared data? If not, what's the
problem with multiple threads executing it at a time?
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too