The current code steals focus from the active window when the reminder is shown. This isn't very nice when the user is typing and might lead to inadvertently closing the window (Pressing Enter while typing will Dismiss).
This also happens when the form is reactivated.
private void timerTick(object sender, EventArgs e)
{
updateStartTime();
// Close the form 2 hours after the meeting ends
if (DateTime.Now > meeting.EndTime + new TimeSpan(2, 0, 0))
Close();
else if (DateTime.Now > reactivateTime)
{
// Update the next reactivation time
reactivateTime = DateTime.Now + reactivateTimeSpan;
// Restore the form if minimized, without forcing it to take focus
if (WindowState == FormWindowState.Minimized)
{
logger.Debug("Restoring reminder window after timeout");
// Restore the window without activating it
ShowWindow(this.Handle, SW_RESTORE); // SW_RESTORE = 9, needs PInvoke setup
}
}
}
// You'll need to use Platform Invocation (PInvoke) to call ShowWindow.
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);