3

I have an win-form c# that opens a console application. When i launch the form, which automaticly launches it opens a process

conhost.exe

I tried everything to be able to auto close it, but no solution so far. Any ideas?

this and similar code i tried:

foreach (Process proc in Process.GetProcessesByName("conhost.exe"))
{
    proc.Kill();
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Rien
  • 398
  • 2
  • 12
  • 37

3 Answers3

3

I got to this question by a different route - working on a C# console app that was leaving conhost.exe/vhost.exe running after it should have exited.

Adding an Environment.Exit(0) at the end of processing fixed that.

Dan Field
  • 20,885
  • 5
  • 55
  • 71
0

Are you sure, that the name of the process is conhost.exe? The name is usually different from the name of the executable. You can get the name of the process by accessing proc.ProcessName.

You might want to try something like this:

foreach (Process proc in Process.GetProcessesByName("conhost"))
{
    proc.Kill();
}
Markus Safar
  • 6,324
  • 5
  • 28
  • 44
0

When you want to close the console application you are opening, use the process kill method provided by:

Kill process tree programmatically in C#

Community
  • 1
  • 1
Alex G
  • 718
  • 1
  • 7
  • 9