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 / Interop / October 2005

Tip: Looking for answers? Try searching our database.

STAThread or MTAThread for my .net service ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zvika.ferentz@gmail.com - 28 Oct 2005 22:43 GMT
I've created a ".net service" mainly for database access.
The service consists of 2 threads, the first one uses Interop.SQLDMO
and the second one uses SQLClient and other (third-party) classes .

1. Which attribute should i use for my Main ? does it matter anyway ?
2. When I tried the STAThread, I'm afraid i had some heap-leaks but
when i changed it to MTAThread , it seemed to be ok . can it be or am i
missing something ?

thnx,
Willy Denoyette [MVP] - 30 Oct 2005 12:13 GMT
The STAThread/MTAThread attribute on main in a Windows service is not
relevant, you don't run any COM code in your Main do you?
You have to initialize your (two) service threads apartments explicitely by
setting the AppartmentState to STA or MTA before starting the thread(s).

Willy.

> I've created a ".net service" mainly for database access.
> The service consists of 2 threads, the first one uses Interop.SQLDMO
[quoted text clipped - 6 lines]
>
> thnx,
zvika.ferentz@gmail.com - 30 Oct 2005 14:09 GMT
Hi Willy,

thanks for the quick reply . i guess you are right .
But, i still don't understand - how can i decide if my therad should be
STA or MTA ?

Let's assume that in both threads i'm using Interop.SQLDMO, how can i
tell if this thread-safe COM or not ?
If i ain't wrong - if it's  thread-safe - i can use MTA ,  if it's not
thread-safe - i should specify STA .
Another question that has just come into my mind - How can i use STA if
i don't have any "message pump" mechanism (this is Service, not Form)
... ?

i've read so many articles about it , and i still have so many
questions..:)

thnx again
Willy Denoyette [MVP] - 31 Oct 2005 22:23 GMT
Take a look at SQLDMO with oleview, it should be flagged as 'Apartment'
(STA) or 'Both', anyway it's always safe to set your threads apartment to
STA, you should only set MTA when dealing with 'Free' threaded components.

Willy.

> Hi Willy,
>
[quoted text clipped - 14 lines]
>
> thnx again

Rate this thread:







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.