The program starts, but does not display the interface.

public MainWindow() { Browser.Manage().Window.Maximize(); InitializeComponent(); Main.Content = new Pages.MainPage(); this.Dispatcher.BeginInvoke(new Action(() => { while (true) { RuCaptchaBalance.Text = Rucaptcha.GetBalance(); } })); } 
  • one
    And where is the separate stream here? - Pavel Mayorov
  • Where this.Dispatcher is - Twilight Owl
  • No, this cycle is performed in the main thread - Pavel Mayorov
  • How to make a separate? Tell me, please - Twilight Owl
  • one
    new Thread or Task.Run - Pavel Mayorov

1 answer 1

I think you want this:

 public MainWindow() { Browser.Manage().Window.Maximize(); InitializeComponent(); Main.Content = new Pages.MainPage(); RunMainLoop(); } async void RunMainLoop() { while (true) { RuCaptchaBalance.Text = await Task.Run(() => Rucaptcha.GetBalance()); await Task.Delay(1000); // делаем вычисления не подряд, а через разумную паузу } } 

Regarding the theory of why, read this question .

  • Works, thanks - Twilight Owl
  • @TwilightOwl: Where does it go? You are welcome. - VladD