I use Visual Studio 2017. I work with Windows Form Application, Visual C#. There is a timer with 30 seconds interval in my program. Timer starts at Form_Load event method. Actually i use form load method with some other buttons, new settings have been made, changed user etc. Program writes to a text file some data in timer tick event. I test my application with its release built exe. At the beginning, program writes the text file once at 30 seconds. But it does it 4 times after program run a while, maybe 2 hours later.
Example code:
private void timer1_Tick(object sender, EventArgs e)
{
System.IO.File.AppendAllText(somefilepath, somestringdata + "\r\n");
}
Actually, there is some other processes has to be done at timer event. But they are not about appending the text file. Only the code above is. So can you help me guys? My thought about why it happens, is the setting "Use Parallel Builds". At "Tools -> Options -> Projects and Solutions -> Build and Run" there is an option, "maximum number of parallel project builds". And it is "4" on my settings. Maybe i should do something to make my program run proper with this setting set to 4.
Here's image:
How can i make it work proper? Write to text file just once at 30 seconds as i want and as i coded like.
Edit: I closed and opened program, it writes to textfile just once at 30 seconds. It works how it should, so it is not about the size of textfile. Maybe after a while computer creates another instance of program. Is it possible? If yes, can i make it right with Mutex?