About Threads and Shared Methods ???

Discussion in 'ASP .Net' started by Gilles Lambert, Apr 26, 2004.

  1. 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 Lambert, Apr 26, 2004
    1. Advertisements

  2. 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.
    Alvin Bruney [MVP], Apr 26, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.