I am writing a course launch of programs on a schedule in C #, type of Windows Forms project. The instructor said to realize through a waitable timer. Here is my code:

private void Form1_Load(object sender, EventArgs e) { string date, time, datenow = DateTime.Now.ToShortDateString(), timenow = DateTime.Now.ToShortTimeString(), way; // MessageBox.Show(DateTime.Now.ToShortTimeString()); // MessageBox.Show(timenow); Process p = new Process(); using (StreamReader fs = new StreamReader(@"C:\Users\Master\Documents\Visual Studio 2013\Projects\Cursovaya OS 1\Cursovaya OS 1\bin\Debug\datetime")) { while (!fs.EndOfStream) { // Читаем строку из файла во временную переменную. date = fs.ReadLine(); //time = fs.ReadLine(); way = fs.ReadLine(); p.StartInfo.FileName = way; DateTime utc; utc=Convert.ToDateTime(date); // MessageBox.Show(utc.ToString()); long duetime = utc.ToFileTime(); handle = CreateWaitableTimer(IntPtr.Zero, true, "WaitableTimer"); SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true); uint INFINITE = 0xFFFFFFFF; int ret = WaitForSingleObject(handle, INFINITE); p.Start(); } 

But the process does not start. The format of the file is the date and time, as well as the path to the file:

 08.03.2017 9:20 D:\Des1.txt 

Help please understand the problem.

  • one
    Lord, what a horror. WaitFirSingleObject? And why not ordinary await Task.Delay() ? - VladD
  • @VladD This is the coursework, teachers often need to do it the way they were taken 8-10 years ago. This is the norm in the current education. - V. Birkos
  • @ V.Birkos: Well, it is as if yes. But in this case it makes sense to learn how to do it correctly, to gain courage and correct the teacher. The teacher is also a person, he may be wrong. - VladD
  • @VladD Not every teacher admits that he is wrong, even after long trials with weighty arguments and evidence (They are extremely inadequate, or I was just so lucky). So in some cases it is better to do as he wants, to surrender everything to him and forget about him. But, of course, each case is individual) If the teacher is adequate in communication, you can prepare well and try to correct it, I agree. - V. Birkos
  • @VladD And who decided that this is wrong. More than once I saw so-called tasks on "so solve it without using this one". The usual practice of artificial constraints. Generally a useful practice that develops the ability to solve problems outside the box. - vitidev

0