diff --git a/MesETL.App/HostedServices/MainHostedService.cs b/MesETL.App/HostedServices/MainHostedService.cs index 2b1f7b2..046d87b 100644 --- a/MesETL.App/HostedServices/MainHostedService.cs +++ b/MesETL.App/HostedServices/MainHostedService.cs @@ -181,7 +181,7 @@ public class MainHostedService : BackgroundService new { 条目 = "耗时", 值 = elapsedTime.ToString("F2") + " 秒" }, new { - 条目 = "平均输出速度", + 条目 = "平均处理速度", 值 = (_context.OutputCount / elapsedTime).ToString("F2") + " 条记录/秒" }, new { 条目 = "内存占用峰值", 值 = _context.MaxMemoryUsage + " 兆字节" } diff --git a/MesETL.App/Services/DataRecordQueue.cs b/MesETL.App/Services/DataRecordQueue.cs index c8ab985..3ee4056 100644 --- a/MesETL.App/Services/DataRecordQueue.cs +++ b/MesETL.App/Services/DataRecordQueue.cs @@ -52,8 +52,14 @@ public class DataRecordQueue : IDisposable { var charCount = record.FieldCharCount; LongestFieldCharCount = Math.Max(LongestFieldCharCount, charCount); - if(_currentCharCount + charCount > _maxCharCount) - await TaskExtensions.WaitUntil(() => _currentCharCount + charCount < _maxCharCount, 50); + if (_currentCharCount + charCount > _maxCharCount) + { + // 不用Task.WaitUntil是为了防止产生Lambda闭包 + while (!(_currentCharCount + charCount < _maxCharCount)) + { + await Task.Delay(50); + } + } _queue.Add(record); Interlocked.Add(ref _currentCharCount, charCount); OnRecordWrite?.Invoke(); diff --git a/MesETL.App/Services/ETL/CsvReader.cs b/MesETL.App/Services/ETL/CsvReader.cs index d5b7a99..e825ee3 100644 --- a/MesETL.App/Services/ETL/CsvReader.cs +++ b/MesETL.App/Services/ETL/CsvReader.cs @@ -133,7 +133,7 @@ public class CsvReader : IDataReader if (!hasQuote && currChar == delimiter) { - result.Add(source[start..(end)].ToString()); + result.Add(source[start..(end)].ToString()); // 超大型字符串会在LOH中分配内存,没救 start = end + 1; ++end; }