Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Threading and Forms: NotSupportedException - Use Control.Invoke?
    text
    copied!<p>I am trying to run an application with at least two threads: One form for the user interface and one or more worker threads. They are jointly reading/writing from a static class through a number of other classes. </p> <p>This is why I am passing an instance of the worker class to the display form. I guess that is why it goes wrong for me: </p> <pre><code> public class CoCoon { private Screen displayForm; private Worker worker; public ThreadedApp() { worker = new Worker (1024); displayForm = new Screen(worker); } public void Run() { //thread 1: display form Thread screenThread = new Thread(() =&gt; Application.Run(displayForm)); //thread 2: background worker Thread workerThread = new Thread(worker.Run) {IsBackground = true}; screenThread.Start(); Thread.Sleep(1000); //if I don't wait a while, I get an ObjectDisposedException! workerThread.Start(); } </code></pre> <p>The threads and objects are initiated just fine, but as soon after the Form_Load method is has been handled, an error is thrown on the Application.Run(displayForm) line above. It is an NotSupportedException, with a remark that I should use Control.Invoke. But I am not sure I understand, because I am not letting threads other than the display form's use the controls on it. </p> <p>I am new to threading. Can anyone help me on my way? Thanks!</p> <p>PS: One detail - I am developing this for the Windows Mobile platform. </p> <p><strong>EDIT</strong> After popular request hereby the Stack Trace</p> <pre><code> at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)\r\n at System.Windows.Forms.Control.get_Visible()\r\n at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)\r\n at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n at System.Windows.Forms.Application.Run(Form fm)\r\n at CoCoonWM6.CoCoon.&lt;Run&gt;b__1()\r\n </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