.net消息循环
任何人都可以帮助解释如何在WPF中与消息循环交互? 我知道如何使用它
System.Windows.Threading.Dispatcher.Run()
现在,我只需要一种方法来调用它。 我有一个while循环,我想从它处理消息循环中的消息。
while (state == DebuggerStaus.Waiting) { Thread.Sleep(10); //>> Here I want to call a message loop << }
等待你的建议。 最好的祝福。
PS我需要能够在线程处于while循环时将方法INVOKE引入此线程。 这是我的主要目标。
您需要在WPF线程上创建的控件上执行此操作:
Action myAction = () => { textEdit1.Text = "Counter = " + (i++); }; textEdit1.Dispatcher.Invoke(myAction);
尝试
Thread dispatcherThread = Thread.Current// or thread that dispatcher is running on var dispatcher = Dispatcher.FromThread(dispatcherThread); dispatcher.Invoke(myAction);