CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Com within Thread

    Quote 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.

  2. #17
    Join Date
    May 2002
    Location
    Phoenix, AZ
    Posts
    95

    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/

  3. #18
    Join Date
    Dec 2003
    Posts
    244

    Re: Com within Thread

    Thanks alot!!!!!!!!!!!! you closed my all remaining queries.

  4. #19
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Com within Thread

    Quote Originally Posted by navinkaus
    Thanks alot!!!!!!!!!!!! you closed my all remaining queries.
    You are welcome...

  5. #20
    Join Date
    Dec 2003
    Posts
    244

    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.

  6. #21
    Join Date
    Dec 2003
    Posts
    244

    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.

  7. #22
    Join Date
    Dec 2003
    Posts
    244

    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

  8. #23
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Com within Thread

    Quote 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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured