tags:

views:

45

answers:

2

I have a parent program that calls a worker console app when and update is found to update the files, this application gets the process ID from the parent via arguments and then calls WaitForExit(). What I wish to know is what would be the best way of then restarting that process, would simply calling Proc.Start() be the best way of doing this? Ex:

static void Main(string[] args)
{
    if (args.Length == 2)
    {
        int ParentID = Convert.ToInt16(args[1]);
        Process ParentProc = Process.GetProcessById(ParentID);
        ParentProc.WaitForExit();
        Console.WriteLine(UpdateHandler.GetUpdates(
            Path.GetDirectoryName(ParentProc.MainModule.FileName), args[0]));
        ParentProc.Start();
    }
    else
        Console.WriteLine("Error: Invalid number of arguments.");
}

Or should I create a new process to launch it (I would assume using ParentProc.MainModule.FileName)

I would also like to know if there is a managed way to get the parent process not via arguments?

Thanks :)

+1  A: 

See http://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way

Jerome
Thanks, don't know how I didn't see that. I would put this as the accepted answer, lacks answer to the main problem so: Upvote.
Blam
Nevermind, I just used a workaround, I'll set this as the accepted answer for trying to help :)
Blam
+1  A: 

Ok nevermind, I did this by passing the executable path to the update program to act as both update path and process to relaunch. I did this for two reasons:

  1. The Solution linked to in Jerome's answer is slow, this way is faster.

  2. I had issues with 64bit and 32bit clashing when trying to get the file name via MainModule.FileName (even though I had set both programs as x86)

Blam