在后台调度WPF和运行它 [英] WPF Dispatcher and Running it in background

查看:388
本文介绍了在后台调度WPF和运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想换调度员在一个线程。但结果不是我所期望的。我怎样才能解决这个问题。



 公共无效启动()
{
的ThreadStart TS =内?;
螺纹包装=新主题(TS);
wrapper.Start();
}

私人无效内()
{
_Runner.Dispatcher.Invoke(_Runner.Action,DispatcherPriority.Normal);
}


解决方案

您还没有表现出我们足够代码/解释得足够好,能够提供一个很好的答案,但我的猜测的你的动作( _Runner.Action )是昂贵的,慢执行。如果是这样,这就是为什么你的UI没有响应。你基本上告诉调度运行UI线程上昂贵的操作,当你真正想要做的是在后台线程地运行尽可能多的操作,然后通过<$ C回元帅到UI线程$ C>调度只在必要时。


I tried to wrap the dispatcher in a thread. But the result is not what i expect. How can i solve that problem?

    public void Start()
    {
        ThreadStart ts = inner;
        Thread wrapper = new Thread(ts);
        wrapper.Start();
    }

    private void inner()
    {
        _Runner.Dispatcher.Invoke(_Runner.Action, DispatcherPriority.Normal);
    }

解决方案

You have not shown us enough code/explained yourself well enough to be able to provide a good answer, but I'm guessing your action (_Runner.Action) is expensive and slow to execute. If so, that is why your UI is unresponsive. You're essentially telling the Dispatcher to run that expensive operation on the UI thread when what you really want to do is run as much of your operation on the background thread as possible, and then marshal back to the UI thread via the Dispatcher only when necessary.

这篇关于在后台调度WPF和运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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