C#等待1秒
发布时间:2020-12-16 00:17:17 所属栏目:百科 来源:网络整理
导读:是否有像睡眠(秒)这样的功能,但它不会阻止UI更新? 我有一个这样的代码,如果我把线程睡眠后(letters.Children [Words [index] .index]作为TextBlock).Text = Words [index] .LetterCorrect; (之后我想睡觉)它只等待1秒然后UI获得更新,但我不想要那样. privat
是否有像睡眠(秒)这样的功能,但它不会阻止UI更新?
我有一个这样的代码,如果我把线程睡眠后(letters.Children [Words [index] .index]作为TextBlock).Text = Words [index] .LetterCorrect; (之后我想睡觉)它只等待1秒然后UI获得更新,但我不想要那样. private void Grid_Click(object sender,RoutedEventArgs e) { if (index == Words.Count() - 1) return; if ((((e.Source as Button).Content as Viewbox).Child as Label).Content.ToString() == Words[index].LetterCorrect) { (letters.Children[Words[index].index] as TextBlock).Text = Words[index].LetterCorrect; letters.Children.Clear(); LoadWord(++index); this.DataContext = Words[index]; } } 解决方法
尝试一个Timer并让Elapsed回调执行你想要在一秒钟后发生的代码.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |