开发者

Multithreading on a file open copy and write

I am new at threads here is the question,

I ha开发者_JAVA百科ve 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜