private void ChooseWindowButton_Click(object sender, RoutedEventArgs e) { ChooseWindowButton.ContentStringFormat = "Выбор окна..."; ChooseWindowButton.IsEnabled = false; _targetWindow = IntPtr.Zero; _leftTop = Point.Empty; _width = 0; _height = 0; _chooseWindowThread = new Thread(() => { bool isRightWindow = false; do { IntPtr handle = WindowService.GetForegroundWindow(); string header = WindowService.GetWindowText(handle); if (header.StartsWith("NoxPlayer")) { _targetWindow = handle; _windowHeader = header; isRightWindow = true; } else { Thread.Sleep(500); } } while (!isRightWindow); Dispatcher?.Invoke(() => { ChooseWindowButton.ContentStringFormat = "Выбрать"; ChooseWindowButton.IsEnabled = true; SetElementsState(true); UpdateActions(); ActionsGrid.ItemsSource = Actions; }); }); _chooseWindowThread.Start(); }