Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Invoke Failing on Thread Function
    text
    copied!<p>I'm using a timer to regularly read-in a log file and post certain contents to a textbox in a Windows Form Application I'm developing in C#. I do this by sending a string to set_textbox_thread which posts the text (s) to the appropriate textbox (tbc) in the else below. The code below works in the practice application I built. However, the same code runs, but fails to update my textbox in the full application I'm building. It seems to be failing on the Invoke statement, which fails to call set_textbox_thread again. My theory is that, because my full application has a more complex set of controls, I am not calling Invoke via the correct control. I've tried calling it via "this" the parent panel, the parent form, and the button that triggers set_textbox_thread, and am dealing with the same outcome. Two questions:</p> <ol> <li>Which control should I call Invoke under?</li> <li>Is there a way to retrieve "the thread that owns the controls underlying windows handle? Can I do this through the Controls.Owner method?</li> <li>I have tried making this Invoke call using try/catch, but am unable to retrieve an error message in the catch. Any ideas how to resolve the issue this way?</li> </ol> <p>Thanks in advance!</p> <pre><code>private delegate void stringDelegate(string s); private void set_textbox_thread(string s) { TextBox tbc = get_thread_tb(); if (tbc.InvokeRequired) { MessageBox.Show("Invoke Required"); stringDelegate sd = new stringDelegate(set_textbox_thread); **this.Invoke(sd, new object[] {s });** MessageBox.Show("Invoke Completed"); } else { </code></pre>
 

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