How to show WPF controls during run script

edited August 2020

I wrote following code

foreach(var item in names)
    var button = new System.Windows.Controls.Button { Content = item };
    button.Click += (sender, args) => button.Content = "I've just been clicked!";
    while( ...smth... ) Thread.Sleep(100);

I wait for that code show button and wait my click to continue, but show nothing. if I remove while with sleep then I show all buttons at once. How to show WPF controls during run script?


  • Replace the call to Thread.Sleep with:

    await Task.Delay(1000);

    Another option, if you need just a simple button and not a WPF button, is to use LINQPad's HTML controls, i.e., LINQPad.Controls.Button:

    var button = new LINQPad.Controls.Button ("test") { IsMultithreaded = true };
    button.Click += (sender, args) => button.Text = "I've just been clicked!";
Sign In or Register to comment.