From 35fe7dc36d9167d685f4beab1351190324622b05 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 2 Jan 2022 21:57:35 +1300 Subject: [PATCH] [WIP] Tweaked Action callback Now instead of needing to be specified within the main Program file, we now have something that is defined and run from the SingleInstance class. I'll be adding the code to actually handle the different commandline options shortly. --- DisplayMagician/Program.cs | 2 +- DisplayMagician/Properties/AssemblyInfo.cs | 4 ++-- DisplayMagician/SingleInstance.cs | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index 3bf65ae..75961df 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -64,7 +64,7 @@ namespace DisplayMagician { // Create the remote server if we're first instance, or // If we're a subsequent instance, pass the command line parameters to the first instance and then - bool isFirstInstance = SingleInstance.LaunchOrReturn(otherInstance => { MessageBox.Show("got data: " + otherInstance.Skip(1).FirstOrDefault()); }, args); + bool isFirstInstance = SingleInstance.LaunchOrReturn(args); if (isFirstInstance) { Console.WriteLine($"Program/Main: This is the first DisplayMagician to start, so will be the one to actually perform the actions."); diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index ca5b77c..bc85008 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.1.5.17")] -[assembly: AssemblyFileVersion("2.1.5.17")] +[assembly: AssemblyVersion("2.1.5.19")] +[assembly: AssemblyFileVersion("2.1.5.19")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagician/SingleInstance.cs b/DisplayMagician/SingleInstance.cs index cfaaa10..a978bd0 100644 --- a/DisplayMagician/SingleInstance.cs +++ b/DisplayMagician/SingleInstance.cs @@ -10,6 +10,7 @@ using System.Security.Cryptography; using System.Security.Principal; using System.Text; using System.Threading; +using System.Windows.Forms; using System.Xml.Serialization; namespace DisplayMagician @@ -37,6 +38,12 @@ namespace DisplayMagician private static string GetMutexName() => $@"Mutex_{UniqueName}"; private static string GetPipeName() => $@"Pipe_{UniqueName}"; + public static void executeAnActionCallback(string[] args) + { + MessageBox.Show("got data: " + String.Join(" ",args)); + } + + /// /// Determines if the application should continue launching or return because it's not the first instance. /// When not the first instance, the command line args will be passed to the first one. @@ -45,9 +52,9 @@ namespace DisplayMagician /// Will not run on the main thread, marshalling may be required. /// Arguments from Main() /// true if the first instance, false if it's not the first instance. - public static bool LaunchOrReturn(Action otherInstanceCallback, string[] args) + public static bool LaunchOrReturn(string[] args) { - _otherInstanceCallback = otherInstanceCallback ?? throw new ArgumentNullException(nameof(otherInstanceCallback)); + _otherInstanceCallback = executeAnActionCallback; if (IsApplicationFirstInstance()) { @@ -160,7 +167,7 @@ namespace DisplayMagician } catch (Exception ex) { - Console.WriteLine($"SingleInstance/NamedPipeServerCreateServer: Exception "); + Console.WriteLine($"SingleInstance/NamedPipeServerCreateServer: Exception - Source: {ex.Source} {ex.TargetSite} - {ex.Message} - {ex.StackTrace}"); } // Begin async wait for connections _namedPipeServerStream.BeginWaitForConnection(NamedPipeServerConnectionCallback, _namedPipeServerStream);