laitt
asked on
Start second Form with WebBrowser control in a new thread
I have 2 forms, Form1 is the main form, the second is IEForm with a WebBrowser control.
Pls check the code below, when I run the project I got this error message: "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."
I tried to turn off LoaderLock check in Debug / Exceptions, the LoaderLock error then disappeared but IEForm now doesnt display.
I'm so confused, pls help me to resolve this issue.
Thank you very much.
Pls check the code below, when I run the project I got this error message: "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."
I tried to turn off LoaderLock check in Debug / Exceptions, the LoaderLock error then disappeared but IEForm now doesnt display.
I'm so confused, pls help me to resolve this issue.
Thank you very much.
namespace Test_Thread
{
public partial class Form1 : Form
{
public Thread ieThread;
public IEForm xForm;
...........................................
public void ThreadTask()
{
xForm = new IEForm();
xForm.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
ieThread = new Thread(new ThreadStart(this.ThreadTask));
ieThread.SetApartmentState(ApartmentState.STA);
ieThread.IsBackground = false;
ieThread.Start();
}
}
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.