Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,I have a problem. I have a project based multi-thread. All threads have webbrowser control.
The project works fine on single thread. But when i am trying to work on multi-thread, i get AccessViolationException. There is "document.GetElementById();" expression on line of exception thrown. Does anyone have an idea?
Posted
Updated 11-Jul-14 5:42am
v2

1 solution

You cannot use nor create instances of the webbrowser control on any thread other than the UI (startup) thread.

You also cannot touch, in any way at all, any control on a form from anything other than the UI thread.

If you must set properties and call methods on UI controls from other threads you have to Invoke methods on the UI thread to do so.

C# Invoke method on UI thread[^]
 
Share this answer
 
Comments
Regaloq 11-Jul-14 20:19pm    
Hi i have a second form and it contains webbrowser. Then i starting a new thread and creating second form like below:
Thread t = new Thread(()=>
{
Application.Run(secondForm);
secondForm.Webbrowser.Document.GetElementById(""); // thrown AccessViolationException
});
t.SetApartmanState(ApartmanState.STA);
t.Start();

It works fine but if thread count are two it throwed exception

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