Reputation: 1077
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
Upvotes: 1
Views: 2335
Reputation: 1077
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
Upvotes: 0
Reputation: 1077
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
Upvotes: 0
Reputation: 22148
Look at the Process object. You would just call Process.Start like so:
System.Diagnostics.Process.Start("updater.exe");
Upvotes: 3