What is the best way, to detect if a C# Winforms application has been idle for a certain period of times?
If a user decides to ALT+TAB and do some work with Microsof
You would need to decide what "idle" means. I assume no mouse or key input received by the application during the required time.
You could add a message filter that will see all application-wide Windows messages. See Application.AddMessageFilter. Check for the message codes for key down and mouse down, and record the last time that they occur, but return false so that all messages are handled as normal by the runtime. Likely codes are:
WM_LBUTTONDOWN = 513
RBUTTONDOWN = 516
WM_KEYDOWN = 256
Then in a separate timer elsewhere check when the last event is more than 30 minutes ago.
There are also potential issues with "terminating" the application. If the application has modal forms open, it sounds as if it might not be in a particularly safe state to kill abruptly.