1

I have a Button and use binding to a string (Name property from class Person)

I have the following code:

person1.name = "Name1";
Thread.Sleep(1000);
person1.name = "Name2";

With Binding I only see: Name2 after runtime.

I want to see Name1 then after 1 second see Name2!

How can I realize this? Whats the best method for this?

I also want to use the MVVM - Pattern if this is important.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
RayRayRay
  • 35
  • 5

1 Answers1

0

Use ThreadPool like this:

person1.name = "Name1";
ThreadPool.QueueUserWorkItem(_ =>
{
     Thread.Sleep(1000);

     Dispatcher.BeginInvoke(new Action(() =>
     {
         person1.name = "Name2";
     }));
});

Here you can find another post about ThreadPool in more details.

Community
  • 1
  • 1
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109