开发者

.net message loop

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()

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. I need to be able to INVOKE methods into this thread while the thread is being in while-loop. That is my开发者_开发知识库 main goal.


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);


Try

Thread dispatcherThread = Thread.Current// or thread that dispatcher is running on
var dispatcher = Dispatcher.FromThread(dispatcherThread);
dispatcher.Invoke(myAction);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜