Right Now, it outputs 00, instead of 54. I'm learning with threads and I stuck here, I don't know what to do now
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Point[] array = new Point[20];
public Form1()
{
for (int i = 0; i < 20; i++)
{
array[i] = new Point(); // I'm creating objects here
}
InitializeComponent();
}
void function1()
{
array[0].x = 5;
array[0].y = 4;
}
void function2()
{
label1.Text = array[0].ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread thread1 = new Thread(function1);
thread1.Start();
Thread.Sleep(500);
function2();
}
}
class Point
{
public int x;
public int y;
public override string ToString()
{
return x.ToString() + y.ToString();
}
}
}
when Im doing it in that way (without another thread)
private void Form1_Load(object sender, EventArgs e)
{
function1();
function2();
}
It works fine, output is 54 thanks