component in main threads used in worker threads 
Author Message
 component in main threads used in worker threads

OK I know the problem but not the solution.

I have worker threads being spawned to call into a function of a class that
is using a member variable set to a VB COM.  I get an access violation
attempting to send data to the component.

It is set up like this

the call that kicks off the processing.
    hThreadHandle = CreateThread(NULL, NULL, HandleFile, (LPVOID)this, NULL,
&dwThreadId);

    DWORD CALLBACK HandleFile(LPVOID param)
    {
         CDirObserver* obj = (CDirObserver*)param;
         obj->Handler();

         return 0;
    }

HRESULT CObserver::Handler(){
...
 strTagName = objFilePen->CorralFile(&strFile); //   flTriggerFile.m_str
    // objFilePen created in the main thread and needs to be called within
the worker threads to hold the file in             // Queue untill it's
sister file is downloaded.  if strTagName gets a return other than NULL
start further processing
...

Quote:
}

Well there is the problem, I can't call to the Component created in the main
thread from the worker even though I am using the this pointer to gain
access to the object of the class. Can someone direct me to the solution.
How can I keep a queueing component that relies on worker threads to
populate it?

Thanks.

Steven



Mon, 13 Oct 2003 23:10:15 GMT  
 component in main threads used in worker threads
err..
That may work but I do not think I was clear on exactly what was going on.

A worker thread is spawned for each file that comes in.  So the queue is set
up outside in the main thread otherwise I would be spawning multiple queues,
one for each file.  I guess the way this should have been approached was to
spawn the worker thread after the file match was determined to exist.  The
only problem there is that the queuing system is within the subclass of the
base class where the thread is being spawned.

the base class does nothing more than determine when a file get plopped in a
directory.  Once this happens I spawn the thread to first figure out which
file was dropped, as there could be other files in the dir already.  Once I
figure out that file I try to pass it to the queuing system to see if the
sister file exists already. If it does I process both if not the file gets
held in queue.  So as you can see I can not create the queue from within the
worker thread.
I can however marshal the interface into the worker threads and go from
there.

Steven Szelei

Quote:
> You need to initialize COM in the worker thread with CoInitialize(Ex),
then
> marshal interface pointer between threads using
> CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream.
> --
> With best wishes,
>     Igor Tandetnik



> > OK I know the problem but not the solution.

> > I have worker threads being spawned to call into a function of a class
> that
> > is using a member variable set to a VB COM.  I get an access violation
> > attempting to send data to the component.

> > It is set up like this

> > the call that kicks off the processing.
> >     hThreadHandle = CreateThread(NULL, NULL, HandleFile, (LPVOID)this,
> NULL,
> > &dwThreadId);

> >     DWORD CALLBACK HandleFile(LPVOID param)
> >     {
> >          CDirObserver* obj = (CDirObserver*)param;
> >          obj->Handler();

> >          return 0;
> >     }

> > HRESULT CObserver::Handler(){
> > ...
> >  strTagName = objFilePen->CorralFile(&strFile); //   flTriggerFile.m_str
> >     // objFilePen created in the main thread and needs to be called
within
> > the worker threads to hold the file in             // Queue untill it's
> > sister file is downloaded.  if strTagName gets a return other than NULL
> > start further processing
> > ...
> > }

> > Well there is the problem, I can't call to the Component created in the
> main
> > thread from the worker even though I am using the this pointer to gain
> > access to the object of the class. Can someone direct me to the
solution.
> > How can I keep a queueing component that relies on worker threads to
> > populate it?

> > Thanks.

> > Steven



Mon, 13 Oct 2003 23:30:11 GMT  
 component in main threads used in worker threads
You need to initialize COM in the worker thread with CoInitialize(Ex), then
marshal interface pointer between threads using
CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream.
--
With best wishes,
    Igor Tandetnik


Quote:
> OK I know the problem but not the solution.

> I have worker threads being spawned to call into a function of a class
that
> is using a member variable set to a VB COM.  I get an access violation
> attempting to send data to the component.

> It is set up like this

> the call that kicks off the processing.
>     hThreadHandle = CreateThread(NULL, NULL, HandleFile, (LPVOID)this,
NULL,
> &dwThreadId);

>     DWORD CALLBACK HandleFile(LPVOID param)
>     {
>          CDirObserver* obj = (CDirObserver*)param;
>          obj->Handler();

>          return 0;
>     }

> HRESULT CObserver::Handler(){
> ...
>  strTagName = objFilePen->CorralFile(&strFile); //   flTriggerFile.m_str
>     // objFilePen created in the main thread and needs to be called within
> the worker threads to hold the file in             // Queue untill it's
> sister file is downloaded.  if strTagName gets a return other than NULL
> start further processing
> ...
> }

> Well there is the problem, I can't call to the Component created in the
main
> thread from the worker even though I am using the this pointer to gain
> access to the object of the class. Can someone direct me to the solution.
> How can I keep a queueing component that relies on worker threads to
> populate it?

> Thanks.

> Steven



Mon, 13 Oct 2003 23:14:18 GMT  
 component in main threads used in worker threads
I get it never mind the last post.
thanks Igor.
Steven

Quote:
> You need to initialize COM in the worker thread with CoInitialize(Ex),
then
> marshal interface pointer between threads using
> CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream.
> --
> With best wishes,
>     Igor Tandetnik



> > OK I know the problem but not the solution.

> > I have worker threads being spawned to call into a function of a class
> that
> > is using a member variable set to a VB COM.  I get an access violation
> > attempting to send data to the component.

> > It is set up like this

> > the call that kicks off the processing.
> >     hThreadHandle = CreateThread(NULL, NULL, HandleFile, (LPVOID)this,
> NULL,
> > &dwThreadId);

> >     DWORD CALLBACK HandleFile(LPVOID param)
> >     {
> >          CDirObserver* obj = (CDirObserver*)param;
> >          obj->Handler();

> >          return 0;
> >     }

> > HRESULT CObserver::Handler(){
> > ...
> >  strTagName = objFilePen->CorralFile(&strFile); //   flTriggerFile.m_str
> >     // objFilePen created in the main thread and needs to be called
within
> > the worker threads to hold the file in             // Queue untill it's
> > sister file is downloaded.  if strTagName gets a return other than NULL
> > start further processing
> > ...
> > }

> > Well there is the problem, I can't call to the Component created in the
> main
> > thread from the worker even though I am using the this pointer to gain
> > access to the object of the class. Can someone direct me to the
solution.
> > How can I keep a queueing component that relies on worker threads to
> > populate it?

> > Thanks.

> > Steven



Mon, 13 Oct 2003 23:31:47 GMT  
 component in main threads used in worker threads
Hello,

IGlobalInterfaceTable is more convenient and effective way if you need
marshal the same interface into few threads.

Cheers,
Vadim.


Quote:
> I get it never mind the last post.
> thanks Igor.
> Steven


> > You need to initialize COM in the worker thread with CoInitialize(Ex),
> then
> > marshal interface pointer between threads using
> > CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream.
> > --
> > With best wishes,
> >     Igor Tandetnik



> > > OK I know the problem but not the solution.

> > > I have worker threads being spawned to call into a function of a class
> > that
> > > is using a member variable set to a VB COM.  I get an access violation
> > > attempting to send data to the component.

> > > It is set up like this

> > > the call that kicks off the processing.
> > >     hThreadHandle = CreateThread(NULL, NULL, HandleFile, (LPVOID)this,
> > NULL,
> > > &dwThreadId);

> > >     DWORD CALLBACK HandleFile(LPVOID param)
> > >     {
> > >          CDirObserver* obj = (CDirObserver*)param;
> > >          obj->Handler();

> > >          return 0;
> > >     }

> > > HRESULT CObserver::Handler(){
> > > ...
> > >  strTagName = objFilePen->CorralFile(&strFile); //
flTriggerFile.m_str
> > >     // objFilePen created in the main thread and needs to be called
> within
> > > the worker threads to hold the file in             // Queue untill
it's
> > > sister file is downloaded.  if strTagName gets a return other than
NULL
> > > start further processing
> > > ...
> > > }

> > > Well there is the problem, I can't call to the Component created in
the
> > main
> > > thread from the worker even though I am using the this pointer to gain
> > > access to the object of the class. Can someone direct me to the
> solution.
> > > How can I keep a queueing component that relies on worker threads to
> > > populate it?

> > > Thanks.

> > > Steven



Fri, 17 Oct 2003 07:45:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. worker thread vs main thread?

2. Handling events from a worker thread in the main thread

3. How to Send messages from worker thread to main thread

4. Synchronization problem between main thread and worker thread

5. Posting a message from a worker thread to the main app thread

6. main GUI thread -vs- Main Frame Thread

7. Posting messages to the main window from worker threads

8. Worker Threads Inside In-Process Components

9. COM Threading Model for ISAPI Worker Threads

10. Exe server threading model - events from worker thread question

11. how do i create thread safe worker thread

12. How can i terminate a Worker Thread during a Thread is running?Thank

 

 
Powered by phpBB® Forum Software