File tree Expand file tree Collapse file tree 2 files changed +4
-11
lines changed
Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms Expand file tree Collapse file tree 2 files changed +4
-11
lines changed Original file line number Diff line number Diff line change @@ -79,8 +79,6 @@ public void Emit(LogEvent logEvent)
7979 {
8080 _buffer . Add ( logEvent ) ;
8181 Interlocked . Exchange ( ref _hasNewMessages , 1 ) ;
82-
83- // Signal the processing task that there are new messages to process
8482 _signal . Set ( ) ;
8583 }
8684
@@ -101,15 +99,16 @@ private void ProcessMessages(CancellationToken token)
10199 var elapsed = now - lastFlush ;
102100 if ( elapsed < flushInterval )
103101 {
104- // Wait for the remaining time, or until a new message arrives
105102 var remaining = flushInterval - elapsed ;
106103 if ( remaining > TimeSpan . Zero )
107104 {
108- _signal . WaitOne ( remaining ) ;
105+ Thread . Sleep ( remaining ) ;
109106 }
110107 }
111108
112- // Take a snapshot and flush
109+ Interlocked . Exchange ( ref _hasNewMessages , 0 ) ;
110+
111+ // Take a snapshot of the current buffer
113112 _buffer . TakeSnapshot ( snapshot ) ;
114113 builder . Clear ( ) ;
115114 foreach ( var evt in snapshot )
Original file line number Diff line number Diff line change @@ -160,12 +160,6 @@ public void Clear()
160160 {
161161 _body . Clear ( ) ;
162162
163- // Prevent unbounded memory retention by the underlying StringBuilder.
164- // When very large log batches have been rendered, the StringBuilder can
165- // grow to hundreds of kilobytes or even megabytes. Although Clear()
166- // resets its length, the backing buffer (Capacity) is retained which
167- // keeps the memory alive until the next Gen-2 GC collection, causing
168- // memory bloat and noticeable GC pauses.
169163 const int maxRetainedBuilderSize = 64 * 1024 ;
170164 if ( _body . Capacity > maxRetainedBuilderSize )
171165 {
You can’t perform that action at this time.
0 commit comments