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

CA1840: Use 'Environment.CurrentManagedThreadId' #3440

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ dotnet_diagnostic.CA1834.severity = warning # not default, increased severity to
# Keep this in sync with the related C# rule: csharp_style_prefer_parameter_null_checking
dotnet_diagnostic.IDE0190.severity = warning # not default, increased severity to ensure it is applied

# CA1840: Use 'Environment.CurrentManagedThreadId'
dotnet_diagnostic.CA1840.severity = warning # not default, increased severity to ensure it is applied

#### C# Coding Conventions ####

# var preferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void WriteLine(PlatformTraceLevel level, string message)
CultureInfo.InvariantCulture,
"{0}, {1}, {2:yyyy}/{2:MM}/{2:dd}, {2:HH}:{2:mm}:{2:ss}.{2:fff}, {5}, {3}, {4}",
ProcessId,
Thread.CurrentThread.ManagedThreadId,
Environment.CurrentManagedThreadId,
DateTime.Now,
ProcessName,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public void Exit(int exitcode)

/// <inheritdoc />
public int GetCurrentManagedThreadId()
{
return Thread.CurrentThread.ManagedThreadId;
}
=> Environment.CurrentManagedThreadId;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public void Exit(int exitcode)

/// <inheritdoc />
public int GetCurrentManagedThreadId()
{
return Thread.CurrentThread.ManagedThreadId;
}
=> Environment.CurrentManagedThreadId;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public void JobsAreProcessedOnABackgroundThread()
{
// Setup the job process handler to keep track of the jobs.
var jobsProcessed = new List<int>();
Action<string> processHandler = (job) => jobsProcessed.Add(Thread.CurrentThread.ManagedThreadId);
Action<string> processHandler = (job) => jobsProcessed.Add(Environment.CurrentManagedThreadId);

// Queue the jobs and verify they are processed on a background thread.
using (var queue = new JobQueue<string>(processHandler, "dp", int.MaxValue, int.MaxValue, false, (message) => { }))
{
queue.QueueJob("dp", 0);
}

Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, jobsProcessed[0]);
Assert.AreNotEqual(Environment.CurrentManagedThreadId, jobsProcessed[0]);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void SetupChannelShouldCreateTimestampedLogFileForHost()
It.IsAny<Dictionary<string, string>>(),
It.Is<TestRunnerConnectionInfo>(
t => t.LogFile.Contains("log.host." + DateTime.Now.ToString("yy-MM-dd"))
&& t.LogFile.Contains("_" + Thread.CurrentThread.ManagedThreadId + ".txt"))));
&& t.LogFile.Contains("_" + Environment.CurrentManagedThreadId + ".txt"))));
#if NETFRAMEWORK
EqtTrace.TraceLevel = TraceLevel.Off;
#else
Expand Down