I have create one file which call total-cost.txt
and I want to compare two time which is current time and time after added minutes.
I have tried and this is my code
private void OverwriteText()
{
DateTime dn = DateTime.Now;
DateTime now= dn.AddMinutes(2);
if (dn > now )
{
dn = now;
string txt = Convert.ToString(TotCostLong);
using (FileStream fs = new FileStream("total-cost.txt", FileMode.Truncate))
{
using (StreamWriter writer = new StreamWriter(fs))
{
writer.Write(txt);
}
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
OverwriteText();
}
In my ideas, if the current time is reached the time which added by 2 minutes it will overwrite the textfile.
For example, current time is 11.30 and after that add 2 minutes into current time which is 11.32. After reached 11.32 the file will overwrite.
If have any ideas or solution provided, I have much appreciated it.