StreamWriter and Multi-threading

  • Thread starter Thread starter José Joye
  • Start date Start date
J

José Joye

I have 2 threads using the same StreamWriter (obtained from
FileInfo.AppendText).
This first thread will always use the WriteLine() method and the second
thread will always use the Flush() method.
At the present, I have protected the access to the StreamWriter using a
Lock() section.

Is this really particular case, is this necessary?
What could be the implication if I remove the Lock() section?

Thanks,
José
 
While one sw is writing to the file, the other one is flushing the buffer?
What are you trying to achieve here?

regards,
Peter
 
In fact the client using my class needs to write information in a file.
However, it has really little time at disposal (I can not flush information
synchrously, it will take too much time). Therefore, the method called by
the client will make a writeline (which does not flush and therefore it is
quick) it will send set an event for an async. thread telling some info
needs to be flush.

Hope this sounds clear?

Do you have an answer to my question?
José
 
Back
Top