Reputation: 315
I have scripts that run on request and are compiled using CodeDomProvider. Here's an example of one:
var yes = SendYesNo();
if (yes)
// Do something
else
// Do something else
Now. SendYesNo displays a box with input from the user. I want to halt the script on that line, until a response is set. And then, take the response and apply it to the variable and continue the execution. So far I've used await/async, but I dislike this idea. Is it possible with something else?
Upvotes: 0
Views: 164
Reputation: 3915
You could use a modal window that returns your parameter. You could either use a standard MessageBox or a customized Form if the input required is more complex.
Something like:
public class SomeForm : Form
{
public bool yesNo
{
get
{
return yesNo;
}
set
{
//set value according to your logic
}
}
}
and in your main Form call it like:
using (var form = new SomeForm())
{
if (form.ShowDialog() == DialogResult.OK)
{
var yesNo = form.yesNo;
if (yes)
// Do something
else
// Do something else
}
}
in case it's just a Yes / No MessageBox you can refer to: How do I create a message box with "Yes", "No" choices and a DialogResult?
Upvotes: 1