当多个启动时,仅杀死一个控制台应用程序

时间:2017-09-29 11:50:19

标签: c# .net visual-studio .net-core

鉴于以下项目:

enter image description here

两个项目(.Net Core 2.0)都在启动时运行:

enter image description here

我试图在不杀死项目KillingTestOtherApp的情况下仅杀死KillingTest应用程序,但是当我在下面运行代码时,两个控制台应用程序都将关闭。

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);
            }
        }
    }
}

我做错了什么?

[编辑]

我在.Netcore github上打开了这个问题:

github.com/dotnet/core/issues/1005

使用.NET Core时,Visual Studio中的调试过程中存在错误,

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

目前没有解决方案(假设我们希望能够调试所有应用程序)。

1 个答案:

答案 0 :(得分:3)

我认为您的问题来自于您让Visual Studio调试这两个程序。因此,当第一个应用程序提交Seppuku时,Visual Studio将终止第二个程序。当我告诉第二个“没有调试时启动”时,它会在第一个终止后继续运行。

Start settings

相关问题