COM & threads 
Author Message
 COM & threads

Hi all!

I wrote a kind of SessionManager - its a Singleton COM component (EXE
server). My SessionManager manages a list of Session objects, each of these
Session objects has a CComPtr p and some numbers as member variables. In the
constructor of the Session object I call p.CoCreateInstance() to create an
object of the desired component. My SessionManager itself has two interface
methods, named CreateSession and ReleaseSession. When the CreateSession
method is called for the first time, I also create a thread in which I start
a timer (using SetTimer()) and run an endless message loop (using
GetMessage) to catch WM_TIMER events. I pass the this-Pointer to this thread
so it can access private class members. When a WM_TIMER event is caught, I
call a private function f of my class which will check the existing session
objects for timeout. Ok, so far so good ...

My problem now is the following: if a timeout is detected, I delete the
pointer to the affected session object. The destructor of the session object
is also called, so one should expect that the CComPtr (member variable of
the session object) should also be released - but it isn't. If I have a look
at my component view, the instances of the components stay alive.
On the other side, if I call the ReleaseSession() method of my
SessionManager directly, everything works fine and the instances are
destroyed. So I assume the problem is the timer thread? The session objects
are all created using the CreateSession() method - which is in the main
thread. Only from time to time the timer thread calls my function f which
checks for expired objects. So maybe COM+ services dont release the objects
as they were created by another thread (the main thread, but the timer
thread got another ID)? But I pass the this-pointer to the thread so it
should be able to access the right instance - and by the way, it's a
singleton so there is only one instance. Does the function f inherit the
thread ID of the timer thread? How can I solve the problem?

Thanks in advance & Regards

Markus



Fri, 20 Feb 2004 18:39:09 GMT  
 COM & threads
Hi again!

After several hours I solved the problem ... you must call
CoInitializeEx(NULL, COINIT_MULTITHREADED)  in the newly created thread to
make it belong to the main thread.

Regards

Markus



Quote:
> Hi all!

> I wrote a kind of SessionManager - its a Singleton COM component (EXE
> server). My SessionManager manages a list of Session objects, each of
these
> Session objects has a CComPtr p and some numbers as member variables. In
the
> constructor of the Session object I call p.CoCreateInstance() to create an
> object of the desired component. My SessionManager itself has two
interface
> methods, named CreateSession and ReleaseSession. When the CreateSession
> method is called for the first time, I also create a thread in which I
start
> a timer (using SetTimer()) and run an endless message loop (using
> GetMessage) to catch WM_TIMER events. I pass the this-Pointer to this
thread
> so it can access private class members. When a WM_TIMER event is caught, I
> call a private function f of my class which will check the existing
session
> objects for timeout. Ok, so far so good ...

> My problem now is the following: if a timeout is detected, I delete the
> pointer to the affected session object. The destructor of the session
object
> is also called, so one should expect that the CComPtr (member variable of
> the session object) should also be released - but it isn't. If I have a
look
> at my component view, the instances of the components stay alive.
> On the other side, if I call the ReleaseSession() method of my
> SessionManager directly, everything works fine and the instances are
> destroyed. So I assume the problem is the timer thread? The session
objects
> are all created using the CreateSession() method - which is in the main
> thread. Only from time to time the timer thread calls my function f which
> checks for expired objects. So maybe COM+ services dont release the
objects
> as they were created by another thread (the main thread, but the timer
> thread got another ID)? But I pass the this-pointer to the thread so it
> should be able to access the right instance - and by the way, it's a
> singleton so there is only one instance. Does the function f inherit the
> thread ID of the timer thread? How can I solve the problem?

> Thanks in advance & Regards

> Markus



Sat, 21 Feb 2004 04:48:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Threading Problem w/ VB6, VC6, & COM

2. Threading Problem w/ VB6, VC6, & COM

3. Threading & Com calls

4. COM Threading Model for ISAPI Worker Threads

5. com to com and worker threads

6. MFC UI Thread doesnt start when COM method called in multi-threaded MFC dialog App

7. Client Server && Threads

8. Interprocess Communication && Multiple threads of execution

9. (MFC || COM) || (MFC && COM) || What?

10. COM component and Threading

11. multi thread can't work with com+

12. Threads and COM objects

 

 
Powered by phpBB® Forum Software