Let's say I have this class with the RaiseProperyChanged
attribute from PostSharp:
[NotifyPropertyChanged]
public class MainViewModel
{
public int RandInt { get; set; }
public MainViewModel()
{
RandInt = 10;
new Task(TaskStart).Start();
}
private void TaskStart()
{
Random rand = new Random();
while (true)
{
RandInt = rand.Next(9999);
}
}
}
Binding RandInt
to a label or other control wil result in no change of the label. This means that the value of the label will be 10
all the time because the property is changed from another thread. How to handle this strange behaviour? Doing this with MVVM Light with RaisePropertyChanged()
in the setter of the property works fine.