I have a method which save settings to file. This method is called if value of dateTimePicker changed. But I have in Form_Load loading settings -> I read value from file and assign it with dateTimePicker, but this call method save_settings (couse value changed). And in this moment is problem couse the file is open by program -> reading values and program wanna write to file changes... How can I do that?
I think that you have critical section. There are plenty ways to deal with this issue . One way is to put Lock statement around file saving . This way one thread should wait after another thread is finished. But from understanding your question I think that problem is with your desing . As I understand you trying to read and write simultaneously . Maybe you should declare global bool variable isToSave . That will indicate when you can save . When working with file do not forget to use using statement to release file Handle.