Hi
I have some .Html files having (only) pictures and texts. I need to display that .Html files in my windows form. So I rushed towards WebBrowser Control. Once I drop a WebBrowser control in my form, while running application, I got an error of ThreadStateException
What should I do to avoid this So enlighten me about this.
[Included Libraries : using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading;]
Suggestion I learned From Microsoft :
The suggestion is to generate an ActiveX wrapper for shdocvw using the aximp tool. The command line for this tool should be as follows:
aximp c:\windows\system32\shdocvw.dll
This will generate the following assemblies.
Generated Assembly: D:\Syncfusion\faq\HtmlBrowser\HtmlViewer2\SHDocVw.dll Generated Assembly: D:\Syncfusion\faq\HtmlBrowser\HtmlViewer2\AxSHDocVw.dll
Now we can reference these dlls in our project and use AxWebBrowser.
MyProblem :
---------------
On Build, I am facing no problem.But While running mode I got ThreadStateException as folows
ie.,
"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."
I can refer SHDocVw.dll in my project. But I can't get AxSHDocVw.dll. Can anyone help me
Regards
M.N.Ahmed Sahib

WebBrowser Control (VSN 2005 - C#.Net)
Wail_gsm
Larsenal
Hi
It's all about thread problem! I solved .ie I just changed STA into MTA, My problem solved. Thanks for your comments.
Regards
M.N.Ahmed Sahib
Sanchit Bahal
CarmenM
Hi Ahmed,
I am having a similar problem ie. I am using axWebBrowser to display a Tiff Image and it is giving this error ActiveX control ' ' cannot be instantiated because the current thread is not in a single-threaded apartment.
I tried with MTA Thread but its still giving the same error.
I need to display 2 Form Control at the same time in my Win App. The first form is running fine with threading, but the second form which has axWebBrowser is giving problem.
Can you please write to me as to how you have implemented the MTA thread for the Form in which axWebBrowser is placed.
Excerpts of the Code
[
MTAThread] public static void Main(){
Thread.CurrentThread.Name = "BillThread"; MessageBox.Show(Thread.CurrentThread.ApartmentState.ToString()); MyAppContext app = new MyAppContext();app.ImageThread =
new Thread(new ThreadStart(app.AddImageThread));app.ImageThread.Name =
"ImageThread";app.ImageThread.SetApartmentState(
ApartmentState.MTA); MessageBox.Show(app.ImageThread.ApartmentState.ToString());app.ImageThread.Start();
Application.Run(app);}
Thanks in advance
Su