Skip to content

Commit 418171b

Browse files
committed
Now disposes the event handler if a cancellation token is triggered while waiting for the HandleCreated event
1 parent cbb4ae0 commit 418171b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Extensions/RichTextBoxExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ public static void SetRtf(this RichTextBox richTextBox, string rtf, bool autoScr
6363
var mre = new ManualResetEventSlim();
6464
EventHandler eh = (sender, args) => mre.Set();
6565
richTextBox.HandleCreated += eh;
66-
if (richTextBox.IsHandleCreated) mre.Set();
67-
mre.Wait(token);
68-
richTextBox.HandleCreated -= eh;
66+
if (richTextBox.IsHandleCreated) mre.Set();
67+
try
68+
{
69+
mre.Wait(token);
70+
}
71+
finally
72+
{
73+
richTextBox.HandleCreated -= eh;
74+
}
6975
}
7076

7177
if (richTextBox.InvokeRequired)

0 commit comments

Comments
 (0)