日期:2014-05-18 浏览次数:21062 次
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <Button Height="23" Margin="95,0,108,45" Name="button1" VerticalAlignment="Bottom" Click="button1_Click">Button</Button> <TextBlock Margin="38,40,19,88" Name="textBlock1" /> </Grid> </Window>
public partial class Window1 : Window { private delegate void DeleDoWork(); public Window1() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { DeleDoWork work = new DeleDoWork(DoWork); Dispatcher.BeginInvoke(work); } private void DoWork() { for (int i = 0; i < 100; i++) { textBlock1.Text = i.ToString(); Thread.Sleep(200); } } }