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 / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

Question: Using STA component in threadpool via delegate.BeginInvo

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Leon - 20 Oct 2006 07:49 GMT
Hi,

I have a couple of questions relating to STA component that has been bugging
me.

If I have a STA component and I want to call one of its methods, which takes
some times to complete and so I want to run it on a threadpool by using
delegate.BeginInvoke().

Questions:
1) What kind of Apartment are the threads in the threadpool?
2) In legacy COM programming, I need to manually marshal the COM interface
pointer to the other Apartment.

If I simply pass the interface in .Net as a parameter when I call the
delegate.BeginInvoke(), will .Net marshals the interface for me?

If not, how do I to do this correctly?

Thanks.

Leon
Carl Daniel [VC++ MVP] - 20 Oct 2006 17:34 GMT
> Hi,
>
[quoted text clipped - 9 lines]
> Questions:
> 1) What kind of Apartment are the threads in the threadpool?

Generally speaking, they're not in any apartment.  I would assume, however,
that they'll automatically enter the MTA if necessary.  That doesn't help
with your STA component though.

> 2) In legacy COM programming, I need to manually marshal the COM interface
> pointer to the other Apartment.
>
> If I simply pass the interface in .Net as a parameter when I call the
> delegate.BeginInvoke(), will .Net marshals the interface for me?

I don't think so.  Even if it did, it wouldn't do what you want anyway,
since the marshalled interface pointer would simply marshall the call back
into the thread that created the component in the first place - that's the
only thread a STA component can run on.

If you have a STA component, you really don't have any practical alternative
to simply calling all of it's member functions on your UI thread.

-cd

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.