Reputation: 1271
Unhandled exception at 0x0e90a1c0 in MyApp.exe: 0xC0000005: Access violation.
Based in the post How might I create and use a WebBrowser control on a worker thread? I'm trying to run the WebPagePump
class on another thread.
for (int i = 0; i < 5; i++)
{
Thread t = new Thread(delegate() { WebNav1(); });
t.Start();
}
private Action WebNav1 = delegate()
{
WebPagePump a = new WebPagePump();
a.Navigate(new Uri("http://www.mywebsite.com"));
a.Completed += delegate(WebBrowser wb)
{
Console.WriteLine("It's loaded!");
a.Dispose();
};
};
Upvotes: 1
Views: 501
Reputation: 24383
You need to specify a Single Threaded Apartment:
Thread t = new Thread(delegate() { WebNav1(); });
t.ApartmentState = ApartmentState.STA;
t.Start();
Upvotes: 2