P
P
PegaSonic2019-03-27 19:18:47
C++ / C#
PegaSonic, 2019-03-27 19:18:47

How to work with time (C#)?

When I run the form, this code is triggered

private void Form1_Load(object sender, EventArgs e)
        {
            StreamWriter sw = new StreamWriter(@"c:\windows\file.txt", true);
            sw.WriteLine("изи");
            sw.Close();
        }

How to make "easy" delete from file.txt after 20 minutes?
(I don't know the line number)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2019-03-27
@PegaSonic

Few data.
1) What happens if there is no access to the file?
2) What happens if the disk runs out of space?
3) What will happen if the program is closed, and there can be no talk of any 20 minutes?
4) Which line to delete if there are thousands of identical ones?
5) What happens if after 20 minutes the file is no longer on the disk?
To delete a file by the same process that created/updated it, it must run for more than 20 minutes.
If this is not possible, then you need to create another program that after 20 minutes will remove the desired text from it. And launch it with a job.
If we are talking about a task for ourselves, then you can simply use Timer .
There are 4 types of timers in C#, they are described in the link above.
System.Timers.Timer
System.Threading.Timer
System.Windows.Forms.Timer
System.Web.UI.Timer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question