Advertisement
GlobalAccessSoftware

Program Main for 2nd Instance Messages to 1st.

Jul 4th, 2022
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//
  2. // Program.cs 02-Sep-2017
  3. // 21-Feb-2018  MyEditor.Smesa
  4. //\\//\\//\\//\\//\\//\\//\\//\\//\\//
  5. // SMESAV Solution Started v1.0.1.00
  6. // v1.0.1.02 02-Sep-2017
  7. // v1.0.1.11 18-Oct-2017
  8. // v1.1.2.26 12-Nov-2017 Solid Rocket
  9. // v2.2.5.26 28-Dec-2017 Multi-Tabs
  10. // v2.3.8.29 26-Jan-2018 Pass in Parms
  11. // v2.5.9.30 04-Feb-2018 Release Tests
  12. // v2.5.9.31 10-Feb-2018 Simplified.
  13. // v2.6.0.32 15-Feb-2018 1351 Stocker
  14. // v2.6.1.33 21-Feb-2018 1620 Mutexed
  15. // v3.0.0.01 25-feb-2018 As WPF App.
  16. // Experimental to pass args to an
  17. // active 1st instance Smesa from a
  18. // 2nd Instance Last Chance v3.0
  19. // v3.0.0.37 28-Feb-2018 Hybrid.
  20. // Working Model with hybrid strategy
  21. // v3.1.1.38jamorama 07-Mar-2018 2332
  22. //\\//\\//\\//\\//\\//\\//\\//\\//\\//
  23.  
  24. using System;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Threading;
  28. using System.Diagnostics;
  29. using System.Windows.Forms;
  30.  
  31. using SMS = MyEditor.Properties.Settings;
  32. using SMR = MyEditor.Properties.Resources;
  33.  
  34. namespace MyEditor
  35. {
  36.   static class Program
  37.   {
  38.     private static bool _1St;
  39.     public static Mutex MyMutex =
  40.       new Mutex(false, "Smesa", out _1St);
  41.  
  42.     private static bool ProcessCheck()
  43.     {
  44.       var processes =
  45.         Process.GetProcessesByName(
  46.           Process.GetCurrentProcess()
  47.             .ProcessName).ToList();
  48.       if (processes.Count > 1
  49.         && SMS.Default.Testing)
  50.         // testcode has not been seen so
  51.         // far; as OpenWith isn't an Option.
  52.           MessageBox.Show(SMR.ProcChck);
  53.       return processes.Count < 2;
  54.     }
  55.  
  56.     /// <summary> v3.1.1.38
  57.     /// 04-Mar-2018 1715 MmfIpc Mods
  58.     /// CopyRight (c) 2018 Jp Edwards
  59.     /// </summary>
  60.     [STAThread]
  61.     static void Main()
  62.     {
  63.       if (_1St)
  64.       {
  65.         if (!ProcessCheck()) return;
  66.         Application.EnableVisualStyles();
  67.         Application
  68.           .SetCompatibleTextRenderingDefault
  69.           (false);
  70.         Application.Run(
  71.           new Smesa(Args(), Mmfn()));
  72.         MyMutex.Dispose();
  73.       }
  74.       else Main2();
  75.       // For ALL Secondary Instances.
  76.     }
  77.  
  78.     private static void Main2()
  79.     {
  80.       Application.Run(
  81.         new Smesa(Mmfn(), Args()));
  82.     }
  83.  
  84.     private static string Mmfn()
  85.     {
  86.       var root = SMS.Default.AppRoot =
  87.         Directory.GetCurrentDirectory();
  88.       SMS.Default.Save();
  89.       return root + "\\mmf.sme";
  90.     }
  91.  
  92.     private static string[] Args()
  93.     {
  94.       return
  95.         Environment.GetCommandLineArgs();
  96.     }
  97.  
  98.  
  99.   }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement