views:

168

answers:

1

Hi, 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 ?

+2  A: 

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.

Chris Arnold
thanks for answer, I am using 3 threads because our teacher wants this,I am new at multithreading.
e-turhan
Use threads by all means, it stops your UI freezing, but they need to be run in order.
Chris Arnold