|
-
November 17th, 2005, 09:50 AM
#16
Re: Com within Thread
 Originally Posted by navinkaus
Siddhartha, so do you mean without marshalling it will work ?
I mean that I have never seen it not work when interface pointers are not marshalled across threads - so long as the thread initializes COM using CoInitialize before using the same, things work fine.
-
November 17th, 2005, 10:48 AM
#17
Re: Com within Thread
You will need the message loop, when you marshal the interface pointer, and then unmarshal and use it in a different thread. This is because the proxy and stub communicate via windows messages.
If you dont marshal / unmarshal the interface pointer, it may or may not work across appartments - but you loose the synchronization which com provides for components in STAs.
Prosise has published 2 really nice articles on code guru, which should probably explain things clearly
http://www.codeguru.com/Cpp/COM-Tech...cle.php/c5529/
and
http://www.codeguru.com/Cpp/COM-Tech...cle.php/c5533/
-
November 17th, 2005, 11:01 AM
#18
Re: Com within Thread
Thanks alot!!!!!!!!!!!! you closed my all remaining queries.
-
November 17th, 2005, 11:53 AM
#19
Re: Com within Thread
 Originally Posted by navinkaus
Thanks alot!!!!!!!!!!!! you closed my all remaining queries.
You are welcome...
-
November 17th, 2005, 10:59 PM
#20
Re: Com within Thread
hey.....got some new questions...but think these are stupid questions they are very much good questions I found on google earlier I was thinking that I am putting stupid questions. anyways my questions are:
1. At what point I need to put message loop if my code looks like this in thread
object->Method1
object->Method2
object->Method3
I think I need to put the message loop in end.
2. Since I know that at a time only one thread will use the com object still I need to do marashalling and use message loop.
-
November 18th, 2005, 12:11 AM
#21
Re: Com within Thread
Here are the result of my R & D.
1. Without Marashalling
If you don't use Marashalling there is no problem in my sample application.
It does not give you gurantee of serialization. it can call methods either first in main thread or in child thread. In other words order of calling method is not fixed ( serialised )
Even you can use WaitForSingleObject for serialisation.
2. With Marashalling
It gives you gurantee of serialisation.
You can not use WaitForSingleObject ( otherwise it will be in deadock )
Here interesting thing is: In my case whether I use message loop or not does not effect at all.
This is my R & D till now. You comments will be highly appreciated.
-
November 18th, 2005, 12:46 AM
#22
Re: Com within Thread
Now I tell you what I concluded. There is no benefit of thread in case of STA.
As in case of STA , you need marashalling to use the object across the threads, and you calls get serialized.
Now since your calls get serialized your main thread stucks till your child thread ends processing. So my user will not see the dialog so in this case it is better not to use the thread.
Now the answer of milliion dollar question, "I worte previously that it works without using marashalling" This is incorrect as sometimes difficult to re-produce you stuck in thread forever.
So across the threads you need to use marashallling with message loop.
In summary, there is no benefit of using thread in case of STA
-
November 18th, 2005, 07:41 AM
#23
Re: Com within Thread
 Originally Posted by navinkaus
In summary, there is no benefit of using thread in case of STA
Please do note - you forgot to add 'In my case'. 
There are many COM components with STA, which use threads with no troubles. The matter of experience/understanding/suitability/design/etc.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|