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
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