Hi!
So I have a MainForm. There is a timer on that form, and in a right time I want my application to shows four seperate forms with an axWebBrowser on them. These axWebBrowsers are automated with their OnDocumentComplete events. So, first I had the following error message: ...The current thread is not in a single-threaded apartment. So I searched the internet for this error, and corrected my code with this line:
regThread.ApartmentState = ApartmentState.STA;
I dont have 'is not single threaded blabla...' for anymore, but now I have this error:
Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
What does that mean Adn what should I do Can u help me
Many thanks in advance!
Regards!

Problem with axWebBrowser in a Multithreaded application
cdeck
Many thanks for your help. Great article. I think I can solve the problem with it...
Regards!
PablitoMil
cturton
I think we need to back up here. On what thread were you getting the not STA error Are you creating separate threads, or using thread-pool threads
What does the stack trace look like when you receive the "Do not attempt to run managed code inside DllMain" error
Gerhard B
Hello!
Iam very new to this c# thing, so I think the easiest way is if I paste my source code to this place. Here is my thread class:
public class MyThread{
public void myThread(){
Browser_Method =
"METHOD_URLAP"; frmBongeszo fBongeszo = new frmBongeszo(Browser_Method);fBongeszo.Show();
}
}
And here is the code where I start the thread:
Ertek = (myCM.Current
as DataRowView).Row["tbIdopont"];Idopont =
Convert.ToDateTime(Ertek);Most =
DateTime.Now; if (Idopont <= Most){
/*-----Thread inditasa ha id ben van:-----*/ MyThread thr = new MyThread(); Thread regThread = new Thread(new ThreadStart(thr.myThread));regThread.ApartmentState =
ApartmentState.STA;regThread.Start();
}
I want to start 4-5 different forms at the same time. If I remove the axWebBrowser from the form, it works fine. I found a topic about this problem, but as I said Iam very new to this, so I couldn't understand it... I hope you can help me with this...
Thanks, regards!
keeperman
But there are database connections. On the popup windows I just select a company name or other things from a database, but I can't post the company name because I guess I should know its Id. I think the program posts the Id and not the company name for example (my English is very poor, I hope you'll understand my problem). So how can I handle the database connections And how should I know what kind of data to post There is no problem with textBox-s and simple datas but what about database ID's and other things. I really dont much about these things but it seemed so easy with axWebBrowser. This is the component I need. And as I said before I've solved the problem with this component, I just want to use it in threads. I'll have a look after this WebClient thing, but as I said, I dont wanna write the whole code from the beginning...
I cant believe that I'm the only person who wants to use axWebBrowser in seperate threads... Is it truth :-)
Jesse Hose
Try using the WebClient class to post your data instead of using the webbrowser control ...
http://aspalliance.com/236 is worth a read examples are in vb.net but the same concepts apply.
Insecurity
AspiringGeek
Hi!
I have to start more browsers at the same time, because if I start them too late, another company will register the 'product' and it costs too much for my company.
I want to use this Browsers to fill some registration form. The timing is very important, there is no chance to fill one after the other. For example 3-4 products will be free at 10am. I have to register all of them at 10:01 because if I dont there will be another company who registers it.
Now there sits about 10 people in front of the computer, and fills the form at 9:55, and waits until 10:01 and click the submit button... It is a very complicated task.
And sometimes we have to fill these forms at weekends, and this is not a grateful job.
Thanks for your help! (Sorry about my english!)
Regards!
Irshad_ip
Hi Greg!
This webform is very complicated. It has popup windows, comboboxes and many other things. I have worked with this axWebBrowser so much to fill this form. I dont wanna start this work from the beginning.
Anyway, can I do this job with this WebClient class I dont know it.
I've just got your another post. The link you've suggested me is for asp.net application, isn't it My application is a simple windows form application.
I've worked with this application for so long. It works fine except this thread thing. I've left the threading for last and I think it was a mistake, but I really dont want to start this whole thing again from the beginning.
There must be a solution to run threads with axWebBrowser, isn't there
Thanks for your help!
Richard Miller
Its a framework class .. it can work in either winforms or asp.net.
As for the form being very complicated ... eventually it posts its data to the server (a HTTP post) with WebRequest or WebClient you do not deal with all the functionality of handling such things ... you just build the post which contains the data that you want and push it through (all those items are just values in the post being sent to the server)
samo9789
Hi Tamas. You should never have more than one thread communicating with GUI elements. Any particular application starts out with one message pump and this message pump is responsible for synchronizing and queuing messages to that GUI.
If you want to have work done in the background (i.e. not a GUI thread) you can do that; but, you have to communicate back to the single GUI thread in specific ways.
What work do you want to perform on a separate thread You've described four browswer windows; but, not why you have seperate threads.