BackGroundWorker Problem

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi All.

I am trying to implement a BGW for a file save(using word automation), I get a error that tells me to add the StaThreadAttribute to the Main Function, not so hard but I cannot find the Main Function in any of the files.vb or the designer where VB.net builds the code for me, i.e. the same place I find the initialize components code block, and if I put it - it tells me that it already exists - so where do I find it? Using VB.net 2008 Express Ed.

Thanks for the help.
 
You are probably using a COM component in the BGW thread that needs to run in STA. Use a Thread instead of the BGW and use the SetApartmentState method before you run it, see example. I've seen Clipboard object requires STA thread, but I don't know if the Word COM also need this and that this is the object that throws you the error.
 
Thanks JohnH, I have been working on this for days, reading and searching, will work this angle and let you know how it's doing. Guten morgen Bobby, I will have to work on my deutsche for your link - I think I can find that article in english though...

Thanks again.
 
The thread part seems to be working, But get an error 'unable to cast com object', not sure if this is for the thread work or my code for the word automation, thanks for the threading code John, I'll keep on it...
 
Back
Top