等待而不阻塞WPF [英] Wait without blocking WPF

查看:164
本文介绍了等待而不阻塞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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆