How in c# to do the correct handling clicks?

Have form 1, it creates a form 2, form 2 two textbox and button, you need to do so by clicking this button, the data from textbox1 enrolled in variable 1 and variable 2 in textbox2 and the form closed. Form 2 is run in a separate thread. How to implement it? in particular the button1 handler.click += new EventHandler(method);
but method() does not work to get the data from формы2 and close it too.
private void zapusk_form2(object sender, EvantArgs e)
{ 
Thread tr = new Thread(go)
tr.Start();
}
public void go()
{
 Autent Thread = new Thread(aut);
autent.Start();
.......
}
public void aut()
 { 
 Auts Form2 = new Form2();
auts.Show();
 auts.button1.Click += new EventHandler(metod);
}
 public string login;
 public string pass;
 private void metod(object sender, EventArgs e)
{
 login = auts.textBox1.Text;
 pass = auts.textBox2.Text;
auts.Hide();

 }
April 19th 20 at 12:34
2 answers
April 19th 20 at 12:36
Keep project.
Your username in the right way. Note the docking controls in the second form.
And most importantly, select a global object in which the application logic. But to just assign variables. In General as less as possible code in the forms.
https://yadi.sk/d/Usu-r-Bo1955fQ
April 19th 20 at 12:38
In fact Your question - save the values in global variables. You can display them in a separate module.
A bit of lyrics. You have a very non-thread-safe code. To reference controls and forms inside flow always use invoke. Otherwise sudden program crashes with an error. Also for me is not clear - why start a thread that in turn starts another thread...
If the flow is interesting for You, read this wonderful article: https://www.rsdn.org/article/dotnet/CSThreading1.xml

Find more questions by tags Windows FormsC#