run an external exe if that specific exe is not running after sometime - run it

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);
        }
    }

 
}

I fixed it. The following are code changes, there are two fixes to this solution.

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()
    {

       // Invoke("OnStartup", 6); << simple one line code does the trick

    }
    bool isStarted = false;
    void Update()
    {
        //this is also another way

        /* if (Time.realtimeSinceStartup > reUpdate && !isStarted) //7s
         {
            isStarted = true;
            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());
        }
        if (IsProcessOpen(ICEexe) == true)
        {
            UnityEngine.Debug.Log("ICE is running");

        }
     
        

     
        //return;
    }

    IEnumerator RelaunchICE()
    {
        UnityEngine.Debug.Log("Im in IEnumerator waiting for lapse time:" + timetoUpdate);
        yield return new WaitForSeconds(timetoUpdate);
        launchICE();

    }

    void launchICE()
    {
        try
        {
            UnityEngine.Debug.Log("Im in launchICE method, launching" + ICEexe);
            Process.Start(ICEexe);

        }
        catch (System.Exception e)
        {
            print(e);
        }
    }

 
}