Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## Release Notes - Serilog.Sinks.RichTextBox.WinForms.Colored v3.1.1
## Release Notes - Serilog.Sinks.RichTextBox.WinForms.Colored v3.1.2

### What Changed

- Fixed a bug where the TextFormatter would crash when the value or format was null or empty.
- Fixed a bug where cross-thread log messages during form construction caused `System.InvalidOperationException` due to premature access of the RichTextBox.

### Contributors

- [Steffen S. Hellestøl](https://github.com/SteffenSH)

### Resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<TargetFrameworks>net462;net471;net6.0-windows;net8.0-windows;net9.0-windows;netcoreapp3.0-windows;netcoreapp3.1-windows</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseWindowsForms>true</UseWindowsForms>
<Version>3.1.1</Version>
<Version>3.1.2</Version>
<PackageReleaseNotes>
- Fixed a bug where the TextFormatter would crash when the value or format was null or empty.
- Fixed a bug where cross-thread log messages during form construction caused `System.InvalidOperationException` due to premature access of the RichTextBox.

See repository for more information:
https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored
See repository for more information:
https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored
</PackageReleaseNotes>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<SupportedOSPlatform>windows</SupportedOSPlatform>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace Serilog.Sinks.RichTextBoxForms.Extensions
Expand Down Expand Up @@ -54,8 +55,25 @@ private struct Point
private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, int wParam, ref Point lParam);
#endif

public static void SetRtf(this RichTextBox richTextBox, string rtf, bool autoScroll)
public static void SetRtf(this RichTextBox richTextBox, string rtf, bool autoScroll, CancellationToken token)
{
//Wait for richTextBox.Handle to be created
if (!richTextBox.IsHandleCreated)
{
var mre = new ManualResetEventSlim();
EventHandler eh = (sender, args) => mre.Set();
richTextBox.HandleCreated += eh;
try
{
if (richTextBox.IsHandleCreated) mre.Set();
mre.Wait(token);
}
finally
{
richTextBox.HandleCreated -= eh;
}
}

if (richTextBox.InvokeRequired)
{
richTextBox.BeginInvoke(new Action(() => SetRtfInternal(richTextBox, rtf, autoScroll)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void ProcessMessages(CancellationToken token)
{
_renderer.Render(evt, builder);
}
_richTextBox.SetRtf(builder.Rtf, _options.AutoScroll);
_richTextBox.SetRtf(builder.Rtf, _options.AutoScroll, token);
lastFlush = DateTime.UtcNow;
}
}
Expand Down