From 8746702052b3d54aecd4a11f4aaf535b0337829e Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Wed, 1 Mar 2017 11:28:57 +0100
Subject: [PATCH] [KOE-14] Restarter now waits for the Outlook process to
finish before starting a new one.
---
.../Stubs/OutlookWrappers/AddInWrapper.cs | 2 +-
.../OutlookRestarter/Program.cs | 31 +++++++++++++++++--
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
index 8b89d93..5b8aa63 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
@@ -150,7 +150,7 @@ namespace Acacia.Stubs.OutlookWrappers
// Run that
Process process = new Process();
- process.StartInfo = new ProcessStartInfo(path, Environment.CommandLine);
+ process.StartInfo = new ProcessStartInfo(path, Process.GetCurrentProcess().Id + " " + Environment.CommandLine);
process.Start();
// And close us and any other windows
diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs b/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs
index 7f774a4..fb96d83 100644
--- a/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs
+++ b/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs
@@ -17,20 +17,45 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
namespace OutlookRestarter
{
class Program
{
+
+ ///
+ /// Entry point.
+ /// Arguments:
+ /// 0 - parent pid
+ /// 1 - parent path
+ /// 2 - arguments
+ /// n - ...
+ ///
+ ///
[STAThread]
static void Main(string[] args)
{
- Process process = new Process();
- process.StartInfo = new ProcessStartInfo(args[0], string.Join(" ", args.Skip(1)));
- process.Start();
+ string procPath = args[1];
+ var procArgs = args.Skip(2);
+ try
+ {
+ // Attempt waiting for the process to finish
+ int procId = int.Parse(args[0]);
+ Process proc = Process.GetProcessById(procId);
+ proc.WaitForExit(15000);
+ }
+ finally
+ {
+ // Start the process
+ Process process = new Process();
+ process.StartInfo = new ProcessStartInfo(procPath, string.Join(" ", procArgs));
+ process.Start();
+ }
}
}
}