gpt4 book ai didi

c# - 每秒加载新图像

转载 作者:行者123 更新时间:2023-11-30 19:03:13 26 4
gpt4 key购买 nike

我需要每秒(或两个)加载新图像。

以下代码不起作用:

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 秒,然后出现第二张图片。

我该怎么做?谢谢。

最佳答案

为此使用定时器

    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;
}

关于c# - 每秒加载新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5869114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com