Hi all,
This is my attempt at detecting if a specified external exe is running or not and if it is not relaunch after 5 mins/300 seconds. However it spam launches infinitely. What am I doing wrong? Probably missed a silly little thing.
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System.Threading;
public class Handler : MonoBehaviour {
public int reUpdate;
public int timetoUpdate;
public string ICEexe;
// Use this for initialization
void Start()
{
// OnStartup();
}
void Update()
{
if (Time.time > reUpdate) //7s
{
UnityEngine.Debug.Log("Checking if ICEexe is false");
OnStartup();
}
}
public bool IsProcessOpen(string name)
{
foreach (Process copProcess in Process.GetProcesses())
{
if (copProcess.ProcessName.Contains(ICEexe))
{
return true;
}
}
return false;
}
void OnStartup() // other apps on Start()
{
Process currentProcess = Process.GetCurrentProcess();
if (IsProcessOpen(ICEexe) == false)
{
UnityEngine.Debug.Log("ICE not running start coroutine");
StartCoroutine(RelaunchICE());
}
//return;
}
IEnumerator RelaunchICE()
{
UnityEngine.Debug.Log("Im in IEnumerator waiting for lapse time:" + timetoUpdate);
yield return new WaitForSeconds(timetoUpdate);
}
void launchICE()
{
try
{
UnityEngine.Debug.Log("Im in launchICE method, launching" + ICEexe);
Process.Start(ICEexe);
}
catch (System.Exception e)
{
print(e);
}
}
}