user1694345
user1694345

Reputation: 67

C# created files only appear after the program stops

I have a program which will generate a log file every 10 minutes. That program will execute for around 2 months non-stop.

During testing, I found out that the files that were created only appears in the directory after the program was stopped. For example, if i start the program now and stop the execution 50 minutes later, i did not get to see the files in the directory every 10 minutes but i will see all 5 appear at once after i stopped the program.

is there a way to solve this? i would like to see the file every 10 minutes.

the file generation code:

timeDiff = now.Subtract(previous);
if (timeDiff.Minutes >= 10)
{
     StreamWriter sw = File.AppendText(path + "\\file" + i +".txt");
     sw.WriteLine("what ever text");
     sw.Close();
     i++;
}

Many thanks! and pardon for my English. (:

Upvotes: 0

Views: 163

Answers (1)

ziaziosk
ziaziosk

Reputation: 136

You can check the autoflush property Quoting From MSDN

// Gets or sets a value indicating whether the StreamWriter 
// will flush its buffer to the underlying stream after every  
// call to StreamWriter.Write.
sw.AutoFlush = true;    

Upvotes: 1

Related Questions