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

Question about threads and win32 api's ?

P: n/a
Hello all,

I need to call a win32 api and I also need to have a worker
thread in my program. Is there something I should be
carefull of, as in the documentation for 'thread' it reads

"ApartmentState:
Gets or sets the threading model used for a particular thread.
Threading models are important when a thread calls unmanaged code."

Tia.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I had an issue in a program recently which called dtspkg.dll, the DTS Package
Object library (a COM DLL).
The thing that actually did the calling was a worker thread.
When the DTS started, it would work fine for a small number of rows, but
when it got to about 100,000 rows it would crash spectacularly.
I wouldn't have found out what was wrong with it in a million years until I
posted a question here and somebody said it was because I needed to change
the threading model property of the thread to STAThread (out of a possible
STAThread, MTATHread and Unknown).
So the lesson from this is only ever call an STA-threaded COM DLL (which
most apparently are) on an STAThread thread.

Calling APIs though... I believe you can do in any thread whatever its type,
although I may be wrong!

"tt" wrote:
Hello all,

I need to call a win32 api and I also need to have a worker
thread in my program. Is there something I should be
carefull of, as in the documentation for 'thread' it reads

"ApartmentState:
Gets or sets the threading model used for a particular thread.
Threading models are important when a thread calls unmanaged code."

Tia.

Nov 21 '05 #2

P: n/a
O.k., thanks. It's not a com object, just an api, but your info
may be useful in future ....

tt
"Bonj" <Bo**@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
I had an issue in a program recently which called dtspkg.dll, the DTS Package Object library (a COM DLL).
The thing that actually did the calling was a worker thread.
When the DTS started, it would work fine for a small number of rows, but
when it got to about 100,000 rows it would crash spectacularly.
I wouldn't have found out what was wrong with it in a million years until I posted a question here and somebody said it was because I needed to change
the threading model property of the thread to STAThread (out of a possible
STAThread, MTATHread and Unknown).
So the lesson from this is only ever call an STA-threaded COM DLL (which
most apparently are) on an STAThread thread.

Calling APIs though... I believe you can do in any thread whatever its type, although I may be wrong!

"tt" wrote:
Hello all,

I need to call a win32 api and I also need to have a worker
thread in my program. Is there something I should be
carefull of, as in the documentation for 'thread' it reads

"ApartmentState:
Gets or sets the threading model used for a particular thread.
Threading models are important when a thread calls unmanaged code."

Tia.


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.