views:

23

answers:

1

Hi,

I have a vb windows application with 2 forms, where form2 is called from form1 using form2.showdialog()

I added a web browser control to form2, and I'm getting the following error at the point where form2 is called:

Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.

I tried: 1) adding STAThread() to the form_load() 2) I added a module to my application, and created a sub main(), with the STAThread attribute applied to it 3) I marked the sub startup() with STAThread()

And none of this helped.

Any tips on how to get around this issue?

Thanks, rcpg

A: 

If you use the form project template and did not change anything in project settings you don't have control over the main function - the compiler will generate one that has STAThread for you.

Are you creating some objects (such as Timer) in the form whose type has a SynchronizingObject property and you forgot to assign a synchronizing object to it?

Sheng Jiang 蒋晟