About Threads and Shared Methods ???

G

Gilles Lambert

Hi,

I'm not sure about the folowing :

If a shared method writes lines in a text file with a StreamWriter
object during a request, is it possible to have several access
interlaced to the file coming from different request ?

If the answer is yes, is it the same with a general procedure (I guess
yes but i'm not sure). So, in this case, what would be the best : using
a mutex, opening the file in a exclusive way or anything else ?

Thanks and best regards
Gilles
 
A

Alvin Bruney [MVP]

as a general rule, objects are not threadsafe which means they will need to
be protected thru locking or use of the monitor class. Most static
methods/properties are threadsafe (consult the docs to be absolutely
certain). Without locking, the results are truly undetermined ranging from
failed code in win < 2000, to garbled, interlaced text on NT systems. Have a
look at the monitor class, it encapsulates thread protection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top