Hello,
I am a complete beginner. I am trying to find out how to make a program that has an 8 hour timer and when the time elapses it will run an .exe and close itself.
I have managed to do this, but I need to change it so that it won't run the .exe and close itself before 8am. It's a sort of alarm that should wake you up after 8 hours of running the program,
but never before 8am.
Example:
I start the program at 1am.
At 9am the timer elapses, runs Alarm.exe and closes itself.
I start the program at 12am.
At 8am the timer elapses, runs Alarm.exe and closes itself.
I start the program at 11pm. At 7am the timer elapses, but I still want the program to run Alarm.exe and close itself
at 8am.
Thank you very much for your help.
What I have tried:
This is my code so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Timer
{
public partial class Timer : Form
{
public Timer()
{
InitializeComponent();
}
TimeSpan eight = new TimeSpan(8, 0, 0);
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan now = DateTime.Now.TimeOfDay;
if (now >= eight)
{
System.Diagnostics.Process.Start(@"Alarm.exe");
System.Windows.Forms.Application.Exit();
}
else
{
System.Diagnostics.Process.Start(@"Alarm.exe");
System.Windows.Forms.Application.Exit();
}
}