Fixed application process monitoring

Stopped the application threat monitoring halting
the UI completely, which fixed some UI updating
issues. Now UI thread continues to poll waiting for
appl/game to exit, but does it in a loop rather than
blocking using WaitForExit(). Means that the
notification icon gets updated and the UI gets a
MaskedForm over it.
This commit is contained in:
Terry MacDonald 2020-11-22 09:26:17 +13:00
parent ccefa80642
commit dce0ed8252
5 changed files with 58 additions and 39 deletions

View File

@ -593,11 +593,11 @@ namespace HeliosPlus.Resources {
}
/// <summary>
/// Looks up a localized string similar to Selected file is not a valid executable file..
/// Looks up a localized string similar to Selected file is not a valid file..
/// </summary>
internal static string Selected_file_is_not_a_valid_executable_file {
internal static string Selected_file_is_not_a_valid_file {
get {
return ResourceManager.GetString("Selected_file_is_not_a_valid_executable_file", resourceCulture);
return ResourceManager.GetString("Selected_file_is_not_a_valid_file", resourceCulture);
}
}

View File

@ -195,8 +195,8 @@
<data name="Helios_Display_Management" xml:space="preserve">
<value>Helios Display Management</value>
</data>
<data name="Selected_file_is_not_a_valid_executable_file" xml:space="preserve">
<value>Selected file is not a valid executable file.</value>
<data name="Selected_file_is_not_a_valid_file" xml:space="preserve">
<value>Selected file is not a valid file.</value>
</data>
<data name="Executable" xml:space="preserve">
<value>Executable</value>

View File

@ -597,17 +597,22 @@ namespace HeliosPlus
// Look for the processes with the ProcessName we want (which in Windows is the filename without the extension)
processesToMonitor = System.Diagnostics.Process.GetProcessesByName(Path.GetFileNameWithoutExtension(shortcutToUse.DifferentExecutableToMonitor)).ToList();
// TODO: Fix this logic error that will only ever wait for the first process....
// If we have found one or more processes then we should be good to go
// so let's break
if (processesToMonitor.Count > 0)
{
break;
}
// Let's wait a little while if we couldn't find
// any processes yet
Thread.Sleep(300);
ticks += 300;
}
// If none started up before the timeout, then ignore them
// If we have reached the timeout and we cannot detect any
// of the alernative executables to monitor, then ignore that
// setting, and just monitor the process we just started instead
if (processesToMonitor.Count == 0)
{
processesToMonitor.Add(process);
@ -622,22 +627,35 @@ namespace HeliosPlus
if (substringStart < 0)
substringStart = 0;
notifyIcon.Text = $"HeliosPlus: Running {shortcutToUse.ExecutableNameAndPath.Substring(substringStart)}...";
Application.DoEvents();
//Application.DoEvents();
// Wait for the monitored process to exit
while (true)
{
int processExitCount = 0;
// Check each process to see if it's exited
foreach (var p in processesToMonitor)
{
try
{
p.WaitForExit();
if (p.HasExited)
{
processExitCount++;
}
catch (Exception ex)
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"ShortcutRepository/RunShortcut exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
processExitCount++;
}
}
// Make sure that all processes have exited
// then start the shutdown process
if (processExitCount == processesToMonitor.Count)
break;
}
}
else if (shortcutToUse.Category.Equals(ShortcutCategory.Game))
{

View File

@ -42,6 +42,7 @@ namespace HeliosPlus.UIForms
this.lbl_profile_shown_subtitle = new System.Windows.Forms.Label();
this.lbl_profile_shown = new System.Windows.Forms.Label();
this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.tabp_before = new System.Windows.Forms.TabPage();
this.pnl_start_program4 = new System.Windows.Forms.Panel();
this.cb_start_program4 = new System.Windows.Forms.CheckBox();
@ -112,7 +113,6 @@ namespace HeliosPlus.UIForms
this.lbl_title = new System.Windows.Forms.Label();
this.lbl_shortcut_name = new System.Windows.Forms.Label();
this.cb_autosuggest = new System.Windows.Forms.CheckBox();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout();
this.tabp_before.SuspendLayout();
@ -169,7 +169,7 @@ namespace HeliosPlus.UIForms
//
this.dialog_open.DefaultExt = "exe";
this.dialog_open.FileName = "*.exe";
this.dialog_open.Filter = global::HeliosPlus.Resources.Language.Executable_Files_Filter;
this.dialog_open.Filter = "All Files|*.*";
this.dialog_open.RestoreDirectory = true;
this.dialog_open.SupportMultiDottedExtensions = true;
//
@ -253,6 +253,21 @@ namespace HeliosPlus.UIForms
this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip;
this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick);
//
// dv_profile
//
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// tabp_before
//
this.tabp_before.BackColor = System.Drawing.Color.Black;
@ -1070,21 +1085,6 @@ namespace HeliosPlus.UIForms
this.cb_autosuggest.UseVisualStyleBackColor = true;
this.cb_autosuggest.CheckedChanged += new System.EventHandler(this.cb_autosuggest_CheckedChanged);
//
// dv_profile
//
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// ShortcutForm
//
this.AcceptButton = this.btn_save;

View File

@ -234,7 +234,7 @@ namespace HeliosPlus.UIForms
else
{
MessageBox.Show(
Language.Selected_file_is_not_a_valid_executable_file,
Language.Selected_file_is_not_a_valid_file,
Language.Executable,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
@ -484,12 +484,12 @@ namespace HeliosPlus.UIForms
if (rb_wait_alternative_executable.Checked && !String.IsNullOrWhiteSpace(txt_alternative_executable.Text))
{
_executableToUse.ProcessNameToMonitorUsesExecutable = true;
_executableToUse.ProcessNameToMonitorUsesExecutable = false;
_executableToUse.DifferentExecutableToMonitor = txt_alternative_executable.Text;
}
else
{
_executableToUse.ProcessNameToMonitorUsesExecutable = false;
_executableToUse.ProcessNameToMonitorUsesExecutable = true;
}
_shortcutToEdit = new ShortcutItem(
@ -522,6 +522,7 @@ namespace HeliosPlus.UIForms
_executableToUse.ExecutableNameAndPath,
_startPrograms,
_autoName
);
/* _shortcutToEdit.UpdateNoGameShortcut(
Name,
@ -976,7 +977,7 @@ namespace HeliosPlus.UIForms
else
{
MessageBox.Show(
Language.Selected_file_is_not_a_valid_executable_file,
Language.Selected_file_is_not_a_valid_file,
Language.Executable,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
@ -1236,7 +1237,7 @@ namespace HeliosPlus.UIForms
string textToReturn = "";
if (dialog_open.ShowDialog(this) == DialogResult.OK)
{
if (File.Exists(dialog_open.FileName) && Path.GetExtension(dialog_open.FileName) == @".exe")
if (File.Exists(dialog_open.FileName))
{
textToReturn = dialog_open.FileName;
dialog_open.FileName = string.Empty;
@ -1244,7 +1245,7 @@ namespace HeliosPlus.UIForms
else
{
MessageBox.Show(
Language.Selected_file_is_not_a_valid_executable_file,
Language.Selected_file_is_not_a_valid_file,
Language.Executable,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);