等待而不阻塞WPF [英] Wait without blocking WPF
问题描述
我正在尝试实现一种等待情节提要停止的方式,而不会阻塞整个应用程序.
基本上,我有两个情节提要,其中一个用于情节提要和其他用于面板.我想在面板输入和面板输出之间等待几秒钟.
在面板中,我有一个完成的事件处理程序,该事件处理程序执行thread.sleep
请紧记,完成的事件得到
如何在不阻止所有内容的情况下等待动画?
Thx
Nuno
Hi,
I'm trying to implement a way of waiting for an storyboard to stop, without blocking the whole app.
Basicly i have two storyboards, one for panels in and other for panels out. I want to wait a couple of seconds between the panels in and the panels out.
In the panels in i have a completed event handler that does thread.sleep
Strangly, the completed event gets triggered before the animation as really reached its end and everything gets blocked.
How can i make a wait without blocking everything?
Thx
Nuno
推荐答案
尝试使用此方法:
Try using this method:
私有 无效 收益( 长 刻度)
private void Yield(long ticks)
{
// 注意:刻度为100纳秒
// Note: a tick is 100 nanoseconds
长 dtEnd = DateTime .Now.AddTicks(ticks).Ticks;
long dtEnd = DateTime.Now.AddTicks(ticks).Ticks;
而 ( DateTime .Now.Ticks< dtEnd)
while (DateTime.Now.Ticks < dtEnd)
{
this .Dispatcher.Invoke(DispatcherPriority.背景(DispatcherOperationCallback) 委托 ( 对象 未使用){ 返回 null ;}, null );
this.Dispatcher.Invoke(DispatcherPriority.Background, (DispatcherOperationCallback)delegate(object unused) { return null; }, null);
}
}
这篇关于等待而不阻塞WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!