Call function when system time changed
I'm reading the Microsoft SystemEvents.TimeChanged and I'm having trouble understanding how to link my own function to call when the system time changes.
7 Replies
TimeChanged is an event, so you have to += it
SystemEvents.TimeChanged += YourMethod;
and remember to -= it when the program gets closedDoesn’t matter really for app close time.
The problem is my program isn't detecting SystemEvents? Is that a library I import?
It’s in Microsoft.Win32 https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.systemevents?view=net-8.0
SystemEvents Class (Microsoft.Win32)
Provides access to system event notifications. This class cannot be inherited.
You may need a -windows TFM for it.
Eg
net8.0-windows
(that's in the
<TargetFramework>
in your .csproj)I wonder where you set a windows tfm in the VS GUI.