加载新的图像每一秒 [英] Loading new image each second
本文介绍了加载新的图像每一秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要加载每秒(或两个)的新形象。
I need to load each second (or two) new image.
随着code不工作:
System.Threading.Thread.Sleep(2000);
this.Image_LoadImage.Source = new BitmapImage(new Uri(@"D:\\connect2-1.gif"));
System.Threading.Thread.Sleep(2000);
this.Image_LoadImage.Source = new BitmapImage(new Uri(@"D:\\connect3-1.gif"));
我看到的是该应用程序睡4秒钟,然后第二个图像的显示。
What I see is that the app sleeps for 4 seconds and then the second image appears.
我怎样才能做到这一点? 谢谢你。
How can i do it? Thanks.
推荐答案
使用定时器此
private System.Threading.Timer timer;
public MainWindow()
{
InitializeComponent();
timer = new System.Threading.Timer(OnTimerEllapsed, new object(), 0, 2000);
}
private void OnTimerEllapsed(object state)
{
if (!this.Dispatcher.CheckAccess())
{
this.Dispatcher.Invoke(new Action(LoadImages));
}
}
private bool switcher;
private void LoadImages()
{
string stringUri = switcher ? @"D:\\connect2-1.gif" :
@"D:\\connect3-1.gif";
this.Image_LoadImage.Source = new BitmapImage(new Uri(stringUri));
switcher = !switcher;
}
这篇关于加载新的图像每一秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文