static async Task Main(string[] args) { var worker = new Worker.Worker("Data.txt"); int number = 0; await foreach (float res in worker.ReadFile()) { Console.WriteLine($"{number++}: {res}"); } Console.WriteLine("Hello World!"); }
private async void ObButtonReadFile(object sender, RoutedEventArgs e) { int window = 0; if (!int.TryParse(inputWindowSize.Text, out window)) { MessageBox.Show($"Значение ширины окна фильтра должно быть числом", "Ошибка"); return; } Filter filter = null; try { filter = new Filter(window); } catch (Exception ex) { MessageBox.Show($"{ex.Message}", "Ошибка"); return; } worker.FilePath = inputFilePath.Text; loading.Visibility = Visibility.Visible; cancel = new CancellationTokenSource(); chart.ValuesFilter.Clear(); chart.ValuesOrigin.Clear(); ConsoleWrite($"Чтение \"{worker.FilePath}\"..."); try { int count = 0; await foreach (float num in worker.ReadFile(cancel.Token)) { ConsoleWrite($"{count++}: {num}"); chart.ValuesOrigin.Add(num); float?filterResult = filter.TryFilter(num); if (filterResult.HasValue) { chart.ValuesFilter.Add(filterResult.Value); } } float[] finish = filter.Finish(); foreach (var item in finish) { chart.ValuesFilter.Add(item); } ConsoleWrite($"Чтение \"{worker.FilePath}\" завершено"); } catch (OperationCanceledException) { ConsoleWrite($"Чтение \"{worker.FilePath}\" отменено"); } catch (Exception ex) { MessageBox.Show($"{ex.Message}", "Ошибка"); } loading.Visibility = Visibility.Hidden; }