using Processor; namespace UI_WinForms.Components; public sealed partial class TranslationProgress : UserControl { public TranslationProgress() { this.InitializeComponent(); this.DoubleBuffered = true; this.Load += this.OnLoad; AppEvents.WhenTranslationChanged += async (_, _) => await this.TranslationChanged(); } private async void OnLoad(object? sender, EventArgs e) => await this.CalculateTranslationProgress(); private async Task TranslationChanged() => await this.CalculateTranslationProgress(); private async Task CalculateTranslationProgress() { var result = await TranslationProcessor.CalculateTranslationProgress(); if (this.nxProgressBar.InvokeRequired) this.nxProgressBar.Invoke(() => SetProgress(result)); else SetProgress(result); void SetProgress(ProcessorResult resultData) { if (resultData.Successful) this.nxProgressBar.PercentInt = resultData.Result; else this.nxProgressBar.PercentInt = 0; this.nxProgressBar.Refresh(); } } }