You can add a loop to your code, or DispatcherTimer to execute the LongTime. I will show you my demo with use a loop, if you want to use DispatcherTimer, you can refer to the answer.
The Xaml code :
<Window.DataContext>
<local:ViewModel></local:ViewModel>
</Window.DataContext>
<Grid>
<TextBox Text="{Binding Val,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="200" Height="40" Background="Azure"/>
</Grid>
The C# code is:
public class ViewModel : NotifyObject
{
public ViewModel()
{
Val = 0;
Thread thread = new Thread(LongTime);
thread.IsBackground = true;
thread.Start();
}
private int _Val;
public int Val
{
get
{
return _Val;
}
set
{
_Val = value;
OnPropertyChanged("Val");
}
}
public void LongTime()
{
int j = 0;
for (int i = 0; i < 10000000; i++)
{
while (j != 10000000)
{
if (i % 1000 == 0)
{
Val++;
}
j++;
}
}
}
}
The result pictire is:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.