Reven
Reven

Reputation: 776

Kill only one console app, when multiple are started

Given the projects like:

enter image description here

both projects (.Net Core 2.0) are run at startup:

enter image description here

I am trying to kill only KillingTest app without killing project KillingTestOtherApp, but when I am running code below, both console apps are closed.

KillingTest Program.cs

using System;
using System.Diagnostics;

namespace KillingTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var processId = Process.GetCurrentProcess().Id;
            var process = Process.GetProcessById(processId);
            process.Kill();
        }
    }
}

KillingTestOtherApp Program.cs

using System;
using System.Diagnostics;

namespace KillingTestOtherApp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine(Process.GetCurrentProcess().Id);
                System.Threading.Thread.Sleep(100);
            }
        }
    }
}

What am I doing wrong?

[EDIT]

I opened the issue on .Netcore github:

github.com/dotnet/core/issues/1005

it is known bug in debugging process in Visual Studio when using .NET Core,

https://developercommunity.visualstudio.com/content/problem/88707/debugging-multiple-dotnet-core-applications-all-te.html

at present without solution (assuming we want to be able to debug all apps).

Upvotes: 2

Views: 303

Answers (1)

tralmix
tralmix

Reputation: 299

I think your problem comes from the fact you are letting Visual Studio debug both programs. Because of this, when the first app commits Seppuku, Visual Studio is terminating the second program. When I told the second to 'Start without debugging', it continued to run after the first had been terminated.

Start settings

Upvotes: 3

Related Questions