Reousa Asteron
Reousa Asteron

Reputation: 529

Wait for process to exit

How can I wait for a process to finish executing then delete it?

I start the process using Process.Start("process.exe");

Thank you.

Upvotes: 0

Views: 1100

Answers (2)

Ole Albers
Ole Albers

Reputation: 9305

Method One: Just check if the SFXs EXE-Thread is still running. The quick solution would be

 process.WaitForExit();

Method Two: Use Rar und decompress the SFX and check whether the file is still accessed (blocked) periodically.

But I would strictly recommend to use a rar library. So you do not depend on a specific installation of rar (which may even differ depending on the OS)

The following library seems to fit your needs: http://nunrar.codeplex.com/

The library should not care if it is a "real" rar or an sfx file

Upvotes: 0

Alex
Alex

Reputation: 942

You can do the following:

Process proc = Process.Start("update.exe", "-s"); // extract in the silent mode
proc.WaitForExit();
File.Delete("update.exe");

Upvotes: 2

Related Questions