By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Activator.CreateInstance locks in STAThread

P: n/a
Hi,
Does any one know why the creation of a COM object in .NET works when
it runs in the "Main" thread of a console application if the STAThread
tag is used, but same code causes the call to
Activator.CreateInstance(Type) locks up when called from another
thread, even though the thread has been set to STA?

Thanks in advance,
Ashley

Jun 22 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
<as*********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Hi,
Does any one know why the creation of a COM object in .NET works when
it runs in the "Main" thread of a console application if the STAThread
tag is used, but same code causes the call to
Activator.CreateInstance(Type) locks up when called from another
thread, even though the thread has been set to STA?

Thanks in advance,
Ashley

What is the "ThreadingModel" of it's class as it is stored in the registry?

Willy.

Jun 22 '07 #2

P: n/a
What is the "ThreadingModel" of it's class as it is stored in the registry?
>
Willy.
Hi Willy,

I did wonder about this as there is no String value defined for
ThreadingModel in the InprocServer32 KEY for the CLIS of the Object.I
do not have the source for the object, but I know that it is written
in Delphi and is an .ocx file type. Not sure what difference this
makes?I have tried setting the threading apartment to MTA and STA, but
both cause it to hang when calling Activator.CreateInstance. Tried
early binding with a new statement, but again this causes it to hang.

Cheers

Ashley

Jun 22 '07 #3

P: n/a
<as*********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
>What is the "ThreadingModel" of it's class as it is stored in the
registry?

Willy.

Hi Willy,

I did wonder about this as there is no String value defined for
ThreadingModel in the InprocServer32 KEY for the CLIS of the Object.I
do not have the source for the object, but I know that it is written
in Delphi and is an .ocx file type. Not sure what difference this
makes?I have tried setting the threading apartment to MTA and STA, but
both cause it to hang when calling Activator.CreateInstance. Tried
early binding with a new statement, but again this causes it to hang.

Cheers

Ashley
If there is no ThreadingModel specified, then it is considered "Single",
that means that the component is not designed to be accessed from multiple
threads, changing the model toe "Apartment" is in general not a good idea,
as the component was not really designed to live in an STA other than the
'main STA'. The "main STA" is the STA thread created by the COM
infrastructure, not your applications main thread.
Note that I say "Apartment", MTA or STA are NO legal values for
"ThreadingModel". I for one would never use such an object in today's code,
it was written for singled threaded applications, .NET applications are
multi-threaded by default.

Willy.
Jun 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.