views:

131

answers:

2
+2  Q: 

.net message loop

Hi everyone.

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.

A: 

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);
taoufik
Good solution, but not for this case.There is no WPF control in that thread. =(
A: 

Try

Thread dispatcherThread = Thread.Current// or thread that dispatcher is running on
var dispatcher = Dispatcher.FromThread(dispatcherThread);
dispatcher.Invoke(myAction);
Samuel Jack
+1: Neat, didn't know about `Dispatcher.FromThread()`.
Greg D