Use Environment.ProcessId instead of calling a Win32 function #9211
+8
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Use Environment.ProcessId instead of calling a Win32 function. Environment.ProcessId uses the same Win32 function that we were currently using but the difference is that Environment.ProcessId caches the process id instead of doing a PInvoke every time it is accessed (The Win32 function is documented as not changing during the lifetime of the process, see here).
Here's the current implementation of Environment.ProcessId on Windows: https://github.com/dotnet/runtime/blob/60edbf9371ff00349e9224fb0920c8bca51f1a4f/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs#L124.
The goal of this PR is to improve performance by using Environment.ProcessId which caches the value and reduce the complexity of the WPF codebase by using a property from the BCL instead of a Win32 function.
Customer Impact
Better performance.
Regression
No.
Testing
Local testing.
Risk
Low.
Microsoft Reviewers: Open in CodeFlow