XAML
The interface is very simple. There is only one button and one lable element. to click the button, the content of the lable will automatically increase from 0.
<Grid> <Label Name="lable_plus" Content="0"/> <Button Content="Button" Click="button_Click" Height="23" Name="button" Width="75" /></Grid>
C #
private void button_Click(object sender, RoutedEventArgs e){ for (int i = 0; i < 100000; i++) { lable_plus.Content = i; }}
After the above code is executed, you will find that clicking the button does not show up; the number in lable increases progressively, but after a moment, 99999 appears directly. The reason is that the UI thread is blocked to calculate the cyclic I ++.
Method 1:
private void te_Click(object sender, RoutedEventArgs e){ update(); }public delegate void PlusNumberDelegate(int i);private void update(){ for (int i = 0; i < 100000; i++) { this.lable_plus.Dispatcher.BeginInvoke( DispatcherPriority.SystemIdle, new NextNumber(this.plus),i); }}
Reference http://msdn.microsoft.com/zh-cn/library/ms741870.aspx
Method 2:
Real score