Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Activator.CreateInstance locks in STAThread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ash.holland@gmail.com - 22 Jun 2007 13:13 GMT
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
Willy Denoyette [MVP] - 22 Jun 2007 13:37 GMT
> Hi,
> Does any one know why the creation of a COM object in .NET works when
[quoted text clipped - 5 lines]
> Thanks in advance,
> Ashley

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

Willy.
ash.holland@gmail.com - 22 Jun 2007 13:56 GMT
> 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
Willy Denoyette [MVP] - 22 Jun 2007 21:48 GMT
>> What is the "ThreadingModel" of it's class as it is stored in the
>> registry?
[quoted text clipped - 14 lines]
>
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.