Copy data in multithreads c#

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
I still can not decide what is the best way to write snippet if you have example: one main file with lets say accounts and you want to post in random amount of accounts once per day, most important that template should work in multithreads...

With one thread there is no problems at all. I just check today date, bind to date.txt file and then with deleting taking accounts, if file is not there then I create file and copy random amount of accounts in actual day file, and then template continue to work.

BUT if I want to work in multithreads then in one and that same time two or more threads can get File.Exists(path) = false and will create file and will copy random amount of accounts in file. At the end of the day I will have twice as much or even more accounts in file...

Any suggestions ?
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)