using System; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using SimpleRayTracer.Interop; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace SimpleRayTracer { /// /// An empty window that can be used on its own or navigated to within a Frame. /// public sealed partial class MainWindow : Window { private InteropSmokeTest? _smoke; private DispatcherQueueTimer? _timer; public MainWindow() { InitializeComponent(); } private void RunSmokeTestButton_Click(object sender, RoutedEventArgs e) { RunSmokeTestButton.IsEnabled = false; StatusText.Text = "Starting..."; try { _timer?.Stop(); _timer = null; _smoke?.Dispose(); _smoke = new InteropSmokeTest(); _smoke.StartAsync(width: 640, height: 360); RenderImage.Source = _smoke.Bitmap; StatusText.Text = "Rendering..."; _timer = DispatcherQueue.CreateTimer(); _timer.Interval = TimeSpan.FromMilliseconds(33); _timer.Tick += (_, _) => { _smoke?.CopyLatestToBitmap(); if (_smoke?.IsDone == true) { StatusText.Text = "Done"; _timer?.Stop(); } }; _timer.Start(); } catch (Exception ex) { StatusText.Text = ex.Message; RunSmokeTestButton.IsEnabled = true; } } } }