3

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.

user101375
  • 6,961
  • 9
  • 42
  • 43

2 Answers2

0

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);
tofi9
  • 5,775
  • 4
  • 29
  • 50
0

Try

Thread dispatcherThread = Thread.Current// or thread that dispatcher is running on
var dispatcher = Dispatcher.FromThread(dispatcherThread);
dispatcher.Invoke(myAction);
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155