zer0w1dthspace
zer0w1dthspace

Reputation: 1052

Multithreading on a file open copy and write

I am new at threads here is the question,

I have 3 threads one of them calls a method that writes into a file via File.AppendAllText method, other thread duplicates the text in the same file, and the last thread reads the text from file and print on a label.

When I start the threads at the same button click event it gives the error that file is being used by another application, I know why it gives that error but how can I achieve this ?

Upvotes: 0

Views: 684

Answers (1)

Chris Arnold
Chris Arnold

Reputation: 5753

You could chain the threads together. i.e. when thread 1 completes it starts thread 2 etc. etc.

File operations are probably the worst thing you can try to introduce concurrency to and, to be honest, you don't need these 3 threads running at the same time. It actually makes no sense to start all 3 threads at the same time because you don't know in which order they will be run - and this is critical to your operation.

Upvotes: 2

Related Questions