Skip to content

Commit

Permalink
Wpf: Only enable NoGCRegion if not in that mode already
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jul 10, 2024
1 parent 125063e commit 66e41db
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Eto.Wpf/Forms/Controls/TextBoxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,20 @@ public string Text

// Improve performance when setting text often
// See https://github.com/dotnet/wpf/issues/5887#issuecomment-1604577981
if (EnableNoGCRegion)
GC.TryStartNoGCRegion(1000000); // is this magic number reasonable??

TextBox.Text = newText;

if (EnableNoGCRegion && GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
GC.EndNoGCRegion();
var endNoGCRegion = EnableNoGCRegion
&& GCSettings.LatencyMode != GCLatencyMode.NoGCRegion
&& GC.TryStartNoGCRegion(1000000); // is this magic number reasonable??

try
{
TextBox.Text = newText;
}
finally
{
if (endNoGCRegion && GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
GC.EndNoGCRegion();
}

if (needsTextChanged)
{
Callback.OnTextChanged(Widget, EventArgs.Empty);
Expand Down

0 comments on commit 66e41db

Please sign in to comment.