Answer the question
In order to leave comments, you need to log in
Calling an object from another thread?
private void button2_Click(object sender, RoutedEventArgs e)
{
Thread myThread = new Thread(new ThreadStart(Count));
myThread.Start(); // запускаем поток
for (int i = 1; i < 200; i++)
{
label9.Content=(i * i);
Thread.Sleep(300);
}
}
public void Count()
{
for (int i = 1; i < 200; i++)
{
label9.Content=(i * i); // ошибка тут
Thread.Sleep(400);
}
}
Answer the question
In order to leave comments, you need to log in
public void Count()
{
for (int i = 1; i < 200; i++)
{
int local = i * i;
Dispatcher.Invoke(()=>label9.Content = local);
Thread.Sleep(400);
}
}
And what if I have to access 5-10 objects in another thread.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question