In my Windows Form application I have created 2 Forms. In form 1 when I click button1
, a new task will start. Inside the task I have created an instance of the form2
and show form2
. I am calling the showData
Method of Form2
.
//Form1
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(int a1, EventArgs e);
private void button1_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
Form2 form2 = new Form2();
form2.Show();
}
}
//Form2
public void showData(Form1 m)
{
m.Tick += new Form1.TickHandler(test);
}
public void test(int a1,EventArgs e)
{
Task.Factory.StartNew(() =>
{
for (int i = a1; i < 1000; i++)
{
label1.Invoke(new MethodInvoker(delegate { label1.Text = i.ToString(); }));
}
});
}