private void CheckForApps() { try { if (SqlCe.GetAutoEnforceFlag()) { return; } var rApps = CcmUtils.RequiredApps; var allRequiredAppsApps = rApps.Where(x => !x.InstallState.Equals("Installed") && x.Deadline > DateTime.Now.AddMinutes(15)).ToList(); if (allRequiredAppsApps.Count < 1) { Globals.Log.Information($"Wmi didn't return any required applications at this time."); return; } var appDeadline = allRequiredAppsApps.OrderBy(x => x.Deadline).First().Deadline; var allSchedules = SqlCe.GetAllSchedules(); var showToast = false; var featureUpdateExists = false; var dtNextServiceCycle = CommonUtils.GetNextServiceCycleAsDateTime(); foreach (var app in allRequiredAppsApps) { if (allSchedules.Where(x => x.ObjectId.Trim().Equals(app.Id.Trim()) && x.Revision.Trim().Equals(app.Revision.Trim())).Any()) { Globals.Log.Information($"Skipping toast for already scheduled application: '{app.Name}'"); continue; } if (dtNextServiceCycle < app.Deadline) { Globals.Log.Information($"Skipping toast for application covered by service cycle: '{app.Name}'"); continue; } if (app.EvaluationState == 12) { Globals.Log.Information($"Skipping toast for currently installing (possibly long-running) app '{app.Name}'"); continue; } if (app.IsIpuApplication) { featureUpdateExists = true; } showToast = true; } if (dtNextServiceCycle != null) { if (dtNextServiceCycle <= appDeadline) { Globals.Log.Information($"Detected an upcoming service cycle, a Toast notification was suppressed."); return; } } if (showToast && UnsafeNativeMethods.IsUserLoggedOn() && !RegistryMethods.GetIpuIsRunning()) { if (!UnsafeNativeMethods.IsSessionLocked()) { var arg = featureUpdateExists ? "/ToastIpu" : "/ToastApp"; UnsafeNativeMethods.Run(_userApp, $"{arg}", false); } else { Globals.Log.Information($"Detected a locked or non existing user session, a Toast notification was suppressed."); } } } catch (Exception ex) { Globals.Log.Error(ex.Message); } }