Skip to content

Commit

Permalink
CA1840: Use 'Environment.CurrentManagedThreadId' (#3440)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
  • Loading branch information
Evangelink and Evangelink authored Mar 4, 2022
1 parent b280edc commit 358b8b0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
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

0 comments on commit 358b8b0

Please sign in to comment.