views:

55

answers:

4

Hi all! :-)

I'm writing a small updater for my app. My flow would be like this: app.exe -> call process(updater.exe) -> app.close() Then, updater check if app is closed, then overwrites app.exe and other satellite assemblies.

So I need to do something like this: launch my C# exe app, fire a process for updater.exe, then close app, but without closing child process.

There's a way to build this kind of fire-and-forget process in .NET?

Thank you, Nando

+2  A: 

Look at the Process object. You would just call Process.Start like so:

System.Diagnostics.Process.Start("updater.exe");
Steve Danner
Thank you, please read my answer below.
Ferdinando Santacroce
A: 

Use Process.Start method

saurabh
Thank you, please read my answer below.
Ferdinando Santacroce
A: 

Yes, I'm doing so, but seems that Process don't start...

I made a small helper class, called Updater:

Updater.CheckUpdates() 

--> starts a Process who call "updater.exe -check", and that works (when process finished, control return to my main app). I evaluate return code of process, and the I set Updater.UpdatesAvalilable bool flag, if necessary.

Updater.ApplyUpdates()

--> starts a Process who call "updater.exe -update", that do the update work.

So, my code is like this:

    Updater.CheckUpdates();
    if (Updater.UpdatesAvailable)
    {
        Updater.ApplyUpdates();
        System.Environment.Exit(0);
    }

Process in Updater.ApplyUpdates() never run. I know, is not elegant code, but I don't know how to achieve my goal. :-)

Thank you! Nando

Ferdinando Santacroce
A: 

Good morning guys. I found a way to make it work, it seems. In my helper class I wired events for getting stdIO and stdError, just to log something; removing those, I get my work done: process start and main exit! :-)

Just to make all know about it: my process declaration is now like this:

            Process process = new Process();
        process.EnableRaisingEvents = true;

        process.StartInfo = new ProcessStartInfo();
        process.StartInfo.Arguments = "-update";
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.ErrorDialog = false;
        process.StartInfo.FileName = "updater.exe";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();

        process.Start();

Thank you all! Nando

Ferdinando Santacroce