Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Environment.ProcessId instead of calling a Win32 function #9211

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jun 6, 2024

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

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner June 6, 2024 03:01
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jun 6, 2024
@dipeshmsft dipeshmsft self-assigned this Aug 21, 2024
@harshit7962
Copy link
Member

@ThomasGoulet73 Thank you for your contributions.

@harshit7962 harshit7962 merged commit 7f200a3 into dotnet:main Sep 18, 2024
8 checks passed
@ThomasGoulet73 ThomasGoulet73 deleted the use-Environment.ProcessId branch September 19, 2024 00:32
@ThomasGoulet73
Copy link
Contributor Author

Thanks @harshit7962

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants