Click here to Skip to main content
15,885,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm migrating a 32 C#.net windows application for 64 bit system and in my application I'm using MODI for OCRing an image I'm able to migrate the application but the problem is whenever i run the application it gives me an error

"Control 'axMiDocView1' accessed from a thread other than the thread it was created on."

Here's the code Lines where I'm getting this error:


C#
this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axMiDocView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();


Whenever it comes to this.performlayout it throws the exception.


Any Help is appreciated:

Thanks in advance
Posted
Comments
Bernhard Hiller 17-Apr-14 2:15am    
HArd to believe. You do something in a very strange way, I guess. Where is axMiDocView created?

1 solution

This is a very usual issue: instances of certain types or certain facilities can only work in one single thread. This limitation is done to simplify their code. You need to follow this design and execute all corresponding parts of code by the same thread.

It does not mean that you cannot use multiple threads. If you need collaboration between thread, you will need to use thread synchronization and inter-thread communication. In particular, there is an invocation mechanism to delegate some action from one thread to a UI thread. Please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

If you want to develop some non-UI thread to invoke delegates from other thread, you will need to use a loop and create some analogous mechanism. Please see:
http://msdn.microsoft.com/en-us/library/dd267312%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/dd997371%28v=vs.110%29.aspx[^].

In my article, I explained how such things work, without using BlockingCollection:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900