Skip to content

Commit

Permalink
Merge pull request #269 from DreamEnderKing/dev
Browse files Browse the repository at this point in the history
installer: Prevent while loops from consuming a large amount of CPU
  • Loading branch information
ONLOX authored Apr 24, 2024
2 parents 829b7ce + a483e9f commit 09f5ff0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions installer/Data/MD5FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class TVersion
{
// 代码库版本
[JsonInclude]
public Version LibVersion = new Version(1, 0, 0, 0);
public Version LibVersion = new Version(1, 0, 0, 1);
// 选手代码模板版本
[JsonInclude]
public Version TemplateVersion = new Version(1, 0, 0, 1);
public Version TemplateVersion = new Version(1, 0, 0, 2);
// 本体版本
[JsonInclude]
public Version InstallerVersion = new Version(1, 0, 0, 1);
public Version InstallerVersion = new Version(1, 0, 0, 2);
public static bool operator <(TVersion l, TVersion r)
{
return l.LibVersion < r.LibVersion || l.TemplateVersion < r.TemplateVersion || l.InstallerVersion < r.InstallerVersion;
Expand Down
20 changes: 7 additions & 13 deletions installer/Model/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,26 +344,20 @@ public class ListLogger : Logger
protected ConcurrentQueue<LogRecord> Queue = new ConcurrentQueue<LogRecord>();
public ObservableCollection<LogRecord> List = new ObservableCollection<LogRecord>();
public override DateTime LastRecordTime => DateTime.Now;
private Task Timer;
private Timer timer;
private DateTime time;

Check warning on line 348 in installer/Model/Logger.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-install

The field 'ListLogger.time' is never used
private int ind;
public ListLogger()
{
Timer = Task.Run(() =>
ind = 0;
timer = new Timer(_ =>
{
time = DateTime.Now;
ind = 0;
while (true)
for (int i = ind; i < Queue.Count; i++)
{
while ((DateTime.Now - time).TotalMilliseconds <= 100) ;
for (int i = ind; i < Queue.Count; i++)
{
List.Add(Queue.ElementAt(i));
}
ind = Queue.Count;
time = DateTime.Now;
List.Add(Queue.ElementAt(i));
}
});
ind = Queue.Count;
}, null, 0, 100);
}
protected override void Log(LogLevel logLevel, int eventId, string message)
{
Expand Down

0 comments on commit 09f5ff0

Please sign in to comment.