Skip to content

Conversation

@Evangelink
Copy link
Member

_processArtifactFolder = Path.Combine(_fileHelper.GetTempPath(), _testSessionCorrelationId);
_testSessionProcessArtifactFolder = Path.Combine(_processArtifactFolder, $"{Process.GetCurrentProcess().Id}_{Guid.NewGuid()}");
#if NET5_0_OR_GREATER
var pid = Environment.ProcessId;
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it cached by design?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Diagnostics.Process.GetCurrentProcess().Id is expensive:

It allocates a Process instance, usually just to get the Id.
The Process instance needs to be disposed, which has a performance impact.
It's easy to forget to call Dispose() on the Process instance.
If nothing else besides Id uses the Process instance, then the linked size grows unnecessarily by increasing the graph of types referenced.
It is somewhat difficult to discover or find this API.
System.Environment.ProcessId avoids all the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants