我有一个程序可以禁用锁屏并停止 Windows 中的服务。我有两个按钮启用、禁用和一个具有预设时间的组合框。当我的程序运行并且用户单击启用时,程序应该禁用锁定屏幕,直到用户手动单击禁用。我想要完成的是,如果用户从未点击禁用,则让程序不会整夜运行。因此,通过从组合框中选择预设时间,程序将自动禁用它。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DateTime time = DateTime.Today;
for (DateTime _time = time.AddHours(16); _time < time.AddHours(18); _time = _time.AddMinutes(30))
{
comboBox1.Items.Add(_time.ToShortTimeString());
}
}
private static System.Timers.Timer _Timer;
private DateTime _lastRun = DateTime.Now;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string strTime_Start = DateTime.Today.ToString();
string strTime_End = comboBox1.SelectedItem.ToString();
}
public void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = true;
_Timer = new System.Timers.Timer(10 * 60 * 1000);
_Timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
DisableLock();
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (strTime_End < DateTime.Now.Date) //I think this would be where I need to have strTime_End?
{
_Timer.Stop();
_lastRun = DateTime.Now;
}
}
}