From 3134c3575110e6c693f83466eb82d8f627e0585a Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 21 Dec 2023 22:21:20 +0500 Subject: [PATCH] Ban usages of Thread#Sleep (#243) Using Thread.Sleep blocks the _entire_ thread from doing *anything*, while Task.Delay allows the thread to execute other tasks while the delay is passing. The inability to cancel Thread.Sleep may also cause longer shutdowns tl;dr Thread.Sleep bad, Task.Delay good made because of https://github.com/LabsDevelopment/Octobot/pull/234/commits/578c03871de0dd042f2fe0918df296f0a8123e00 Signed-off-by: Octol1ttle --- CodeAnalysis/BannedSymbols.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CodeAnalysis/BannedSymbols.txt b/CodeAnalysis/BannedSymbols.txt index 0a1ec81..bf444a9 100644 --- a/CodeAnalysis/BannedSymbols.txt +++ b/CodeAnalysis/BannedSymbols.txt @@ -18,3 +18,5 @@ P:System.DateTime.Now;Use System.DateTime.UtcNow instead. P:System.DateTimeOffset.Now;Use System.DateTimeOffset.UtcNow instead. P:System.DateTimeOffset.DateTime;Use System.DateTimeOffset.UtcDateTime instead. M:System.IO.File.OpenWrite(System.String);File.OpenWrite(string) does not clear the file before writing to it. Use File.Create(string) instead. +M:System.Threading.Thread.Sleep(System.Int32);Use Task.Delay(int, CancellationToken) instead. +M:System.Threading.Thread.Sleep(System.TimeSpan);Use Task.Delay(TimeSpan, CancellationToken) instead.