Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Detecting Spawned Processes

I'm writing a piece of c# code that launches an installer and waits for it to return before continuing with other stuff.

I'm having trouble with certain installers that spawn other processes with the original process returning before the install has actual finished. Is there some way that I can wait until all the processes have finished?

To clarify here's the scenario I'm having trouble with:

  1. Launch Installer1
  2. Installer1 spawns/launches another installer (Installer2)
  3. Installer 1 returns
  4. Application thinks install has finished but Installer2 is still running. This causes issues with workflow in the app.

Here's the code I'm using at the moment:

// launch installer
Process process = windowsApplicationLauncher.LaunchApplication(_localFilePath);

// wait for process to return
do
{
    if (!process.HasExited)
    {
    }
}
while (!process.WaitForExit(1000));

if (process.ExitCode == 0)
{
    _fileService.MoveFile(_localFilePath, _postInstallFilePath);

    _notification.SetComplete(false);

    return true;
}
return false;
like image 335
tjjjohnson Avatar asked Feb 09 '10 01:02

tjjjohnson


People also ask

Bahasa C digunakan untuk apa?

Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.

C dalam Latin berapa?

C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).

Bahasa C dibuat pertama kali oleh siapa dan tahun berapa?

Bahasa pemrograman C ini dikembangkan antara tahun 1969 – 1972 oleh Dennis Ritchie. Yang kemudian dipakai untuk menulis ulang sistem operasi UNIX. Selain untuk mengembangkan UNIX, bahasa C juga dirilis sebagai bahasa pemrograman umum.


1 Answers

Have you thought about using WMI to solve this problem?

You can use WMI to listen for process creation and deletion events. Question 967668 has a good example.

When you receive a process creation event, you could issue a WMI query to determine if the process is a child (or a child of a child etc) of your root installer with something like the following:

"SELECT * FROM Win32_Process WHERE ParentProcessId=".

like image 78
Antony Perkov Avatar answered Sep 28 '22 13:09

Antony Perkov