[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.
This commit is contained in:
Terry MacDonald 2022-01-02 21:57:35 +13:00
parent a33bd1bf7a
commit 35fe7dc36d
3 changed files with 13 additions and 6 deletions

View File

@ -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.");

View File

@ -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)]

View File

@ -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));
}
/// <summary>
/// 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.</param>
/// <param name="args">Arguments from Main()</param>
/// <returns>true if the first instance, false if it's not the first instance.</returns>
public static bool LaunchOrReturn(Action<string[]> 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);