Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading;
  6. using Avalonia;
  7. using Avalonia.Skia;
  8. using Avalonia.Threading;
  9. namespace ControlCatalog.NetCore
  10. {
  11. static class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. if (args.Contains("--wait-for-attach"))
  16. {
  17. Console.WriteLine("Attach debugger and use 'Set next statement'");
  18. while (true)
  19. {
  20. Thread.Sleep(100);
  21. if (Debugger.IsAttached)
  22. break;
  23. }
  24. }
  25. BuildAvaloniaApp().Start<MainWindow>();
  26. return;
  27. var app = BuildAvaloniaApp().SetupWithoutStarting().Instance;
  28. var src = new CancellationTokenSource();
  29. int cnt = 0;
  30. DispatcherTimer timer = null;
  31. timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, delegate
  32. {
  33. cnt++;
  34. Console.WriteLine("Tick " + cnt);
  35. if (cnt == 3)
  36. {
  37. timer.Stop();
  38. Dispatcher.UIThread.InvokeAsync(() =>
  39. {
  40. Console.WriteLine("Invoked");
  41. src.Cancel();
  42. });
  43. }
  44. });
  45. timer.Start();
  46. app.Run(src.Token);
  47. }
  48. /// <summary>
  49. /// This method is needed for IDE previewer infrastructure
  50. /// </summary>
  51. public static AppBuilder BuildAvaloniaApp()
  52. {
  53. var libraryPath = Path.Combine(Directory.GetCurrentDirectory(),
  54. "../../src/Avalonia.Native.OSX/build/Avalonia.Native.OSX/Build/Products/Debug/libAvalonia.Native.OSX.dylib");
  55. return AppBuilder.Configure<App>().UseAvaloniaNative(libraryPath, opts =>
  56. {
  57. opts.UseGpu = true;
  58. opts.UseDeferredRendering = true;
  59. }).UseSkia();
  60. }
  61. }
  62. }