Using threading to make a function wait until button click in C# : <p>I am having a problem handling threads in my code. I want to make a function wait until the button within its own form is clicked.
A simple scenario looks like this. This is just an overview of my real problem. Suppose that myFunction() is called from another class and uses its returned value.</p>

<pre><code>public class myForm: Form
{   int x=0;
    public dialogForm()
    {
        InitializeComponent();
    }
    public int myFunction() {
        //do something
        //wait for button1's click
        return x;
    } 
  private void button1_Click(object sender, EventArgs e)
    {
       // using this button to change the value of x
       x=2;
    }
</code></pre>

<p>Thanks in advance. Hope anyone helps. </p>
