LINQPad.Controls pause for input

I'm trying out the new LINQPad.Controls and want to dump some radio buttons and then wait for user input before continuing with the rest of the query. What's the best approach for pausing the code here?

For example here's a simple first approach, but are there better alternatives?
void Main()
{
	var radioOne = new RadioButton("group1", "One").Dump();
	var radioTwo = new RadioButton("group1", "Two").Dump();
	var radioThree = new RadioButton("group1", "Three").Dump();

	var btnRun = new Button("Run").Dump();

	btnRun.Click += (sender, args) =>
	{
		if (radioOne.Checked)
		{
			DoSomething("One");
		}
		if (radioTwo.Checked)
		{
			DoSomething("Two");
		}
		if (radioThree.Checked)
		{
			DoSomething("Three");
		}
	};
}

private void DoSomething(string cmd)
{
	cmd.Dump();
}
Many thanks

John

Comments

  • How about this:
    void Main()
    {
        var radioOne = new RadioButton ("group1", "One").Dump();
        var radioTwo = new RadioButton ("group1", "Two").Dump();
        var radioThree = new RadioButton ("group1", "Three").Dump();
    
        new ContinueButton ("Run").Dump().Wait();
    
        if (radioOne.Checked) "Radio1".Dump();
        if (radioTwo.Checked) "Radio2".Dump();
        if (radioThree.Checked) "Radio3".Dump();
    }
    
    public class ContinueButton : Button
    {
        TaskCompletionSource<object> _finished = new TaskCompletionSource<object>();
        
        public Task Task => _finished.Task;
        
        public void Wait() => Task.Wait();
    
        public ContinueButton (string text = "Continue") : base (text)
        {
            IsMultithreaded = true;
            Click += (sender, args) =>
            {
                _finished.TrySetResult (null);
                Visible = false;
            };
        }
    }
    Put the ContinueButton class into My Extensions to use it from any query.
  • Perfect - that works nicely. Thanks very much Joe.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!