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,
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