Warm tip: This article is reproduced from serverfault.com, please click

How to get the current process id of a dotnet core application while it is running?

发布于 2021-02-12 02:48:15

I'm trying to get the processid so I can attach the dotnet core console application to the right process to debug in Visual Studio 2019:

I used the following code in the progress.cs. This code displays a processid but the processid is not listed in the number of dotnet process in Visual Studio 2019.

var currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"ProcessId: {currentProcess.Id}");
Questioner
wonderful world
Viewed
0
wonderful world 2021-02-15 01:34:49

In the latest version of dotnetcore, the Attack to Process will display the application name in the process column. So the processid is not necessary.