in wpf,I have a listbox control and two buttons.I want to be able to use the second button when i clicked the first button till add numbers has not fineshed his work.I use dispatcher.begininvoke but this adds the work on main thread.How to i synchronize this threads?I want to be able to use second button, move the window or using other ui elements when addnumbers processing..
void AddNumbers()
{
for (int i = 1; i <= 1000000; i++)
{
listBox1.Items.Add(i);
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Thread thr = new Thread(new ThreadStart(AddNumbers));
thr.Start();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello World!");
}