Home

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

  • edited July 13
    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.
  • edited July 12

    Hi,
    I'm a relatively inexperienced LINQPader... hit an issue trying to implement this.
    I get an error (even after adding in the Namespace stuff)
    "CS0305 Using the generic type 'TaskCompletionSource' requires 1 type arguments"
    Tried to figure it out consulting the MS documentation, seems I need to add a type... but am out of my depth.

    Is there an update that shows how to do this with a type ?
    Or is there a better way? I just want a button I can click (maybe inside a loop ?) that will then run my query using some user-input parameters. This post seemed real close to providing a mechanism to do that.

    BTW... I am running this in LINQPad 5. Will it be any different under LP 6?
    Thanks,

  • edited July 13

    There was an issue with the markdown editor removing anything in angle brackets. It should be fixed now. The line in question should read:

    TaskCompletionSource<object> _finished = new TaskCompletionSource<object>();
    
  • Thanks Joe... all good now.

Sign In or Register to comment.