Search code examples
.netprocess

How to get the current ProcessID?


What's the simplest way to obtain the current process ID from within your own application, using the .NET Framework?


Solution

  • Get a reference to the current process and use System.Diagnostics's Process.Id property:

    int nProcessID = System.Diagnostics.Process.GetCurrentProcess().Id;