我用 .txt 文件创建了一个字符串列表,然后检查文件是否存在。
最重要的是,我希望标签显示 foreach 正在处理的文件。
尝试过 thread.Sleep 但整个应用程序冻结。我在 WPF 中使用以下代码。
private void Button_Click(object sender, RoutedEventArgs e)
{
List<string> test = new List<string>();
test.Add(@"Files\file1.txt"); test.Add(@"Files\file2.txt"); test.Add(@"Files\file3.txt");
foreach(string t in test)
{
Label2.Content = t;
System.Threading.Thread.Sleep(1000);
if (File.Exists(t))
{
Label2.Content = "yea!";
}
}
}