.NET消息循环 [英] .net message loop

查看:150
本文介绍了.NET消息循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助解释我怎么可以在WPF消息循环互动? 我知道如何使用来启动它

Could anyone help to explain how can I interact with message loop in WPF? I know how to start it using

System.Windows.Threading.Dispatcher.Run()

现在,我只需要一种方法来调用它。 我有一个while循环,我whant从它处理的消息循环消息。

Now, I just need a way to call it. I have a while-loop and I whant to process messages in a message loop from it.

while (state == DebuggerStaus.Waiting)
            {
                Thread.Sleep(10);
                //>> Here I want to call a message loop <<
            }

等待你的建议。最好的问候。

Waiting for your suggestions. Best regards.

P.S。我需要能够调用方法为这个线程,而线程处于while循环之中。这是我的主要目标。

P.S. I need to be able to INVOKE methods into this thread while the thread is being in while-loop. That is my main goal.

推荐答案

您需要做的这是WPF的线程上创建的控件:

You'll need to do that on a control which was created on the WPF thread:

Action myAction = () =>
{
  textEdit1.Text = "Counter = " + (i++);
};
textEdit1.Dispatcher.Invoke(myAction);

这篇关于.NET消息循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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