public partial class Page : UserControl
{
delegate void SetTextCallback(string text);
public Page()
{
InitializeComponent();
TextBlockTest.Text = "5秒钟后变化";
Thread t = new Thread(new ThreadStart(Run));
t.Start();
}
int timer = 5;
private void Run()
{
SetTextCallback call = new SetTextCallback(SetText);
while (timer > 0)
{
timer--;
//call(timer + "秒钟后变化");
this.Dispatcher.BeginInvoke(call, timer + "秒钟后变化");
Thread.Sleep(1000);
}
this.Dispatcher.BeginInvoke(call,"变化结束!");
}
private void SetText(string text)
{
TextBlockTest.Text = text;
}
}