System.Threading.ThreadStateException

Posted by jmls on 26-May-2009 14:19

Got this rather nasty-sounding error. The full message is

System.Threading.ThreadStateException: ActiveX Control '<someGUID>' cannot be instantiated because the current thread is not in a single-threaded apartment.

Thing is, I'm not using threads !

The error is ocurring in a form that has a webbrowser control (.net, not activex) embedded in it.

All Replies

Posted by jmls on 26-May-2009 14:30

Aha! http://support.microsoft.com/kb/841295

Now, the million dollar question: Why an ActiveX ? I am using the .net browser control.

Posted by Peter Judge on 26-May-2009 14:33

Aha! http://support.microsoft.com/kb/841295

Now, the million dollar question: Why an ActiveX ? I am using the .net browser control.

What's the control you're using?

-- peter

Posted by jmls on 26-May-2009 14:40

The one on the "Microsoft Controls" group in Visual designer

Posted by Admin on 26-May-2009 14:45

And what website did you navigate to? Maybe that's using an Active X Control?

Just guessing.

Nachricht geändert durch Mike Fechner

Posted by Peter Judge on 26-May-2009 14:46

[edit] My bad - wrong class from MSDN. You're not using the WebBrowserSite class, just the WebBrowser. Please ignore this comment.

From MSDN, it looks like that control's a wrapper form an ActiveX (see the Remarks): http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.webbrowsersite.aspx

[edit] but I'm still interested in this ...

When do you see the error?

-- peter

Message was edited by: Peter Judge

Posted by jmls on 26-May-2009 14:49

pjudge wrote:

[edit] My bad - wrong class from MSDN. You're not using the WebBrowserSite class, just the WebBrowser. Please ignore this comment.

From MSDN, it looks like that control's a wrapper form an ActiveX (see the Remarks): http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.webbrowsersite.aspx

[edit] but I'm still interested in this ...

When do you see the error?

-- peter

Message was edited by: Peter Judge

The error pops up when it is about to show the page.

Posted by jmls on 26-May-2009 14:50

mikefe wrote:

And why website did you navigate to? Maybe that's using an Active X Control?

Just guessing.

I'll change the site and let you know

Posted by jmls on 26-May-2009 14:57

meh. Tried several - amazon.co.uk, redstore.com etc.

Thing is, I cannot dictate which sites the user can and can't go to

Posted by Admin on 26-May-2009 15:00

You could do using some parental control software.... But is this behaviour site dependent? Would you mind sharing one of the non working sites with us?

Posted by Peter Judge on 26-May-2009 15:38

meh. Tried several - amazon.co.uk, redstore.com etc.

Thing is, I cannot dictate which sites the user can and can't go to

Are those bad sites or good?

I tried them both (and some other sites, like Microsoft's) and they all seemed to work OK, with the attached code.

I should also note my OS etc:

WinXP SP3, IE 6

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/7024.assemblies.xml:550:0]

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/form1.cls:550:0]

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/form1.resx:550:0]

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/start.p:550:0]

-- peter

Posted by Thomas Mercer-Hursh on 26-May-2009 15:52

XP  ...  IE6 .... signs of a person reluctant to modernize?

Posted by jmls on 27-May-2009 01:44

pjudge wrote:

Aha! http://support.microsoft.com/kb/841295

Now, the million dollar question: Why an ActiveX ? I am using the .net browser control.

What's the control you're using?

-- peter

Ah, may have tracked it down. Using the component "standalone" I could not break it at all. However, in the application I am using another component (ipworks xmpp). It seems as this may be the troublemaker. I got another error suggesting that the activex control (again, not using one _unless_ this component is a wrapper) is at fault: 

"This is an ill-behaved multi-threaded control.  It cannot be used with the Progress 4GL. (9179)" .

How can I tell if the component is multi-threaded or a wrapper ? Is there any way of telling if a component is ABL friendly ?

Posted by jmls on 27-May-2009 01:52

bad form to reply to oneself, but this may be of interest to everyone following this thread (ha! geddit ? huh ?)

http://www.nsoftware.com/kb/showentry.aspx?entry=12060401

Posted by Peter Judge on 27-May-2009 08:22

jmls wrote:

bad form to reply to oneself, but this may be of interest to everyone following this thread (ha! geddit ? huh ?)

http://www.nsoftware.com/kb/showentry.aspx?entry=12060401

Interesting. Did you try the suggested workaround?

xmpp1:InvokeThrough = this-object.

-- peter

PS it's good to have a new set of bad puns available to us as ABL developers ...

Posted by jmls on 27-May-2009 08:25

Really spooky - I was literally typing a followup

Yes, it seems to have cured the problem. At least I am not getting any strange errors, and no hanging. One for the KB, methinks !

Thanks to all for the help and suggestions

This thread is closed