private async void Timer_Elapsed(object sender, ElapsedEventArgs e) { if (IsSuspended && SuspensionCause == SuspensionCause.Manual) { // App was manually suspended, only user can unsuspend it return; } if (NeedABreak.Properties.Settings.Default.AutomaticSuspension) { UserNotificationState state = QueryUserNotificationState.GetState(); if (IsSuspended) { // App was automatically suspended, shall we unsuspend it ? if (state == UserNotificationState.AcceptsNotifications) { Resume(); } else { return; } } else { // App is not suspended, shall we automatically suspend it ? switch (state) { case UserNotificationState.Busy: case UserNotificationState.RunningDirect3dFullScreen: case UserNotificationState.PresentationMode: Suspend(SuspensionCause.Automatic); return; } } } double minutesLeft = GetMinutesLeft(); if (minutesLeft <= 0) { await TimesUp(); } else if (minutesLeft <= 1) { await TimesAlmostUp(); } }
private static extern int SHQueryUserNotificationState(out QueryUserNotificationState state);
public static extern int SHQueryUserNotificationState(out QueryUserNotificationState pquns);