0

I have a C# application that creates multiple tasks (class System.Threading.Tasks.Task). Each of these tasks writes to a file, each one writes to a different file from the others, using a different StreamWriter instance.

Microsoft's docs says that: "By default, a StreamWriter is not thread safe."

This means that I could run into problems also in the case described above?

1
  • If each of the thread function writes to a different file using their own copy of the StreamWriter, then yo do not have a problem. Commented Apr 30, 2022 at 9:30

2 Answers 2

2

"StreamWriter is not thread safe." only means that it is not safe to use multiple threads on the SAME StreamWriter instance.

Sign up to request clarification or add additional context in comments.

Comments

1

Since you are saying each task is writing to a different file with its own dedicated instance of StreamWriter, you do not have a problem. You need not do synchronization in your scenario. Only if a single streamwriter instance is used by multiple thread functions then there is a need to do lock based synchronization.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.