dbman1980
dbman1980

Reputation: 1

Multiple instances of StreamWriter working on multiple different disk files in multiple different tasks. Could I run into threading problems?

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?

Upvotes: 0

Views: 127

Answers (2)

Kux
Kux

Reputation: 1489

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

Upvotes: 2

Anand Sowmithiran
Anand Sowmithiran

Reputation: 2920

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.

Upvotes: 1

Related Questions