1

I need to run an external exe "embed.exe" under my WPF project,

here's a snippet

ProcessStartInfo processInf = new ProcessStartInfo("embed.exe");
processInf.Arguments = string.Format(@"Some arguments");
processInf.WindowStyle = ProcessWindowStyle.Hidden;
Process run = Process.Start(processInf);

my problem is that it's block my UI,

is there a way to include embed.exe using a thread or any code that won't block the UI ?

Howa
  • 60
  • 7

2 Answers2

1

OK,

Try to put your previous snippet inside a method, then create a new thread and initialize it to that method.

here's how to make it //hone code

private void EmbedMethod()
{
ProcessStartInfo processInf = new ProcessStartInfo("embed.exe");
processInf.Arguments = string.Format(@"Some arguments");
processInf.WindowStyle = ProcessWindowStyle.Hidden;
Process run = Process.Start(processInf);
}

Thread embedThread=new Thread(EmbedMethod);
embedThread.start();
Omarj
  • 1,151
  • 2
  • 16
  • 43
  • i have a problem now, yes no UI block but after exiting the program the process is still running, how could i terminate it before program termination ? – Howa Feb 16 '13 at 18:19
  • well, i tried to set IsBackground property to true, but still working, the problem is that i created a new process inside a running thread, is there a way to terminate that too ? – Howa Feb 16 '13 at 18:34
0

The process you started is running on its own thread, not the thread your application used to start it.

To terminate your embed.exe process you need to keep a reference to the Process started. In this case the run variable. To terminate the process call either: run.CloseMainWindow() or run.Kill(). Kill forces a termination of the process, while CloseMainWindow only requests a termination.

Steven Licht
  • 760
  • 4
  • 5
  • how do i keep a reference to `run` process out of `EmbedMethod`??,,i found a way to locate that process by searching in `Process.GetProcesses();` list , is there any other way ? – Howa Feb 18 '13 at 07:09