Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few things wrong with your <code>Invoke</code> calls. </p> <ul> <li>You don't need to create an object array to pass the parameters. </li> <li>Passing <code>DispatcherPriority.Normal</code> is redundant (<code>Normal</code> is default). </li> <li>You aren't passing any parameters to the second <code>Invoke</code> method (which is probably where your error is happening).</li> </ul> <p>It should look like this:</p> <pre><code>private void UpdateTextBox(object txt) { if (msg_log.Dispatcher.CheckAccess()) { Dispatcher.Invoke(new UpdateText(UpdateTextBox), txt); } else { msg_log.Dispatcher.Invoke(new UpdateText(UpdateTextBox), txt); } } </code></pre> <p><strong>EDIT For <code>StackOverflowException</code></strong></p> <p>This will cause a <code>StackOverflowException</code> because you are calling your method in an infinite loop. This is happening because your method is simply calling itself over and over again.</p> <p>What <code>Dispatcher.Invoke</code> does is invoke the passed delegate on the thread that owns the <code>Dispatcher</code>. Just because the <code>msg_log</code> may have a different dispatcher, when you were calling <code>UpdateTextBox</code>, you were passing a delegate to the current method, which causes the infinite loop.</p> <p>What you really need to do is call a method on the msg_log object, like so:</p> <pre><code>private void UpdateTextBox(object txt) { if (msg_log.Dispatcher.CheckAccess()) { if (txt != null) msg_log.Text = txt.ToString(); } else { msg_log.Dispatcher.Invoke(new UpdateText(UpdateTextBox), txt); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload