G
Guest
Can anyone tell me why the code below doesn't work? Run the console app and change the system date/time: why is the TimeChanged event handler not executed?
It works fine in a WinForms application, but I can find nothing in the documentation to suggest that the SystemEvents class can only be used in a WinForms app (if this were true, surely it would be in the Windows.Forms namespace).
Thanks,
Joe
using System;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Class1 class1 = new Class1();
Console.Write("Change the system time or Press ENTER to exit");
Console.ReadLine();
}
public Class1()
{
Microsoft.Win32.SystemEvents.TimeChanged +=new EventHandler(SystemEvents_TimeChanged);
}
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
Console.WriteLine("Time changed");
}
}
}
It works fine in a WinForms application, but I can find nothing in the documentation to suggest that the SystemEvents class can only be used in a WinForms app (if this were true, surely it would be in the Windows.Forms namespace).
Thanks,
Joe
using System;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Class1 class1 = new Class1();
Console.Write("Change the system time or Press ENTER to exit");
Console.ReadLine();
}
public Class1()
{
Microsoft.Win32.SystemEvents.TimeChanged +=new EventHandler(SystemEvents_TimeChanged);
}
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
Console.WriteLine("Time changed");
}
}
}