Browse Source

Fix crashes in headless memory benchmark

Nikita Tsukanov 3 years ago
parent
commit
62571a69b6
1 changed files with 8 additions and 2 deletions
  1. 8 2
      samples/ControlCatalog.NetCore/Program.cs

+ 8 - 2
samples/ControlCatalog.NetCore/Program.cs

@@ -56,10 +56,16 @@ namespace ControlCatalog.NetCore
                     .UseHeadless(new AvaloniaHeadlessPlatformOptions
                     {
                         UseHeadlessDrawing = true,
-                        UseComposition = false
+                        UseComposition = true
                     })
                     .AfterSetup(_ =>
                     {
+                        static Task LowPriorityDelay(int ms)
+                        {
+                            return Task.Delay(ms).ContinueWith(_ =>
+                                    Dispatcher.UIThread.InvokeAsync(() => { }, DispatcherPriority.Background))
+                                .Unwrap();
+                        }
                         DispatcherTimer.RunOnce(async () =>
                         {
                             var window = ((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime)
@@ -71,7 +77,7 @@ namespace ControlCatalog.NetCore
                                     continue;
                                 Console.WriteLine("Selecting " + page.Header);
                                 tc.SelectedItem = page;
-                                await Task.Delay(50);
+                                await LowPriorityDelay(20);
                             }
                             Console.WriteLine("Selecting the first page");
                             tc.SelectedItem = tc.Items.OfType<object>().First();