Starting a UI Thread from a UI Thread. 
Author Message
 Starting a UI Thread from a UI Thread.

I'm working with MFC more and more all the time.  Meaning to say the program
started out Win32 only, but now its got all kinds of MFC in it, so...  I
created a UI thread with the ClassWizard and derived from CWndThread (Thats
the name right?) and then created a thread using that New Class with
AfxBeginThread.  All goes great.  Now I created another Class same way using
ClassWizard and deriving from CWndThread.  Now I want to give the Threads
access to each others variables.  Purly for reading data.  Though I can't
seem to create a pointer in CWndThread Ijust created that will point back to
the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.  The
FtpThread gets started and then starts the ScanRecvThread and when that
happens the AfxBeginThread returns the pointer to ScanRecvThred.  Though I
start the ScanRecvThread suspended and initialize its variables, BUT I can't
seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

So This is how I would start (pseudo)
p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
p_ScanRecvThread->p_FtpThread = this;

But I can't seem to create a variable of type p_FtpThread in the new class
even if I include the header at the top?  Is there a better way todo this?

Thanks
Darren King



Sat, 26 Apr 2003 03:00:00 GMT  
 Starting a UI Thread from a UI Thread.

Quote:

> But I can't seem to create a variable of type p_FtpThread in the new class
> even if I include the header at the top?  Is there a better way todo this?

What's the problem?  "can't seem to create" is a pretty vague description :)

--
Scott McPhillips [VC++ MVP]



Sat, 26 Apr 2003 03:00:00 GMT  
 Starting a UI Thread from a UI Thread.
Explain more what you mean by not being able to "create a variable".
What happens? Compile errors? Runtime ASSERTS? (Remember that
cross-thread operations on CWnd objects and CSocket objects don't
work, although you are free to access your own data cross-thread).
                                joe



Quote:
>I'm working with MFC more and more all the time.  Meaning to say the program
>started out Win32 only, but now its got all kinds of MFC in it, so...  I
>created a UI thread with the ClassWizard and derived from CWndThread (Thats
>the name right?) and then created a thread using that New Class with
>AfxBeginThread.  All goes great.  Now I created another Class same way using
>ClassWizard and deriving from CWndThread.  Now I want to give the Threads
>access to each others variables.  Purly for reading data.  Though I can't
>seem to create a pointer in CWndThread Ijust created that will point back to
>the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.  The
>FtpThread gets started and then starts the ScanRecvThread and when that
>happens the AfxBeginThread returns the pointer to ScanRecvThred.  Though I
>start the ScanRecvThread suspended and initialize its variables, BUT I can't
>seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

>So This is how I would start (pseudo)
>p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
>p_ScanRecvThread->p_FtpThread = this;

>But I can't seem to create a variable of type p_FtpThread in the new class
>even if I include the header at the top?  Is there a better way todo this?

>Thanks
>Darren King

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sat, 26 Apr 2003 03:00:00 GMT  
 Starting a UI Thread from a UI Thread.
Oh your right about the socket.  Hmmm..  I'm not sure if that will be a
problem though cause of the way the Socket will work in the Thread, I'll
have to try it.  What I mean is that when I try to create a pointer variable
that is the type of the UIThread inside a UIThread it just simply says
Missing Storage Class or Type Specifiers.  Even though I have an include for
the Class at the top.

Darren King



Quote:
> Explain more what you mean by not being able to "create a variable".
> What happens? Compile errors? Runtime ASSERTS? (Remember that
> cross-thread operations on CWnd objects and CSocket objects don't
> work, although you are free to access your own data cross-thread).
> joe



> >I'm working with MFC more and more all the time.  Meaning to say the
program
> >started out Win32 only, but now its got all kinds of MFC in it, so...  I
> >created a UI thread with the ClassWizard and derived from CWndThread
(Thats
> >the name right?) and then created a thread using that New Class with
> >AfxBeginThread.  All goes great.  Now I created another Class same way
using
> >ClassWizard and deriving from CWndThread.  Now I want to give the Threads
> >access to each others variables.  Purly for reading data.  Though I can't
> >seem to create a pointer in CWndThread Ijust created that will point back
to
> >the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.  The
> >FtpThread gets started and then starts the ScanRecvThread and when that
> >happens the AfxBeginThread returns the pointer to ScanRecvThred.  Though
I
> >start the ScanRecvThread suspended and initialize its variables, BUT I
can't
> >seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

> >So This is how I would start (pseudo)
> >p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
> >p_ScanRecvThread->p_FtpThread = this;

> >But I can't seem to create a variable of type p_FtpThread in the new
class
> >even if I include the header at the top?  Is there a better way todo
this?

> >Thanks
> >Darren King

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Sun, 27 Apr 2003 12:50:33 GMT  
 Starting a UI Thread from a UI Thread.
Sounds like you're missing some minor C/C++ point. Given that it is a
pointer variable, you can always add the declaration in the header
file that gets the error:
        class CMySubUIThread;
so that any use of CMySubUIThread * is properly resolved. The only
time I ever get this error is if I forget either that declaration or
the #include.
                        joe



Quote:
>Oh your right about the socket.  Hmmm..  I'm not sure if that will be a
>problem though cause of the way the Socket will work in the Thread, I'll
>have to try it.  What I mean is that when I try to create a pointer variable
>that is the type of the UIThread inside a UIThread it just simply says
>Missing Storage Class or Type Specifiers.  Even though I have an include for
>the Class at the top.

>Darren King



>> Explain more what you mean by not being able to "create a variable".
>> What happens? Compile errors? Runtime ASSERTS? (Remember that
>> cross-thread operations on CWnd objects and CSocket objects don't
>> work, although you are free to access your own data cross-thread).
>> joe



>> >I'm working with MFC more and more all the time.  Meaning to say the
>program
>> >started out Win32 only, but now its got all kinds of MFC in it, so...  I
>> >created a UI thread with the ClassWizard and derived from CWndThread
>(Thats
>> >the name right?) and then created a thread using that New Class with
>> >AfxBeginThread.  All goes great.  Now I created another Class same way
>using
>> >ClassWizard and deriving from CWndThread.  Now I want to give the Threads
>> >access to each others variables.  Purly for reading data.  Though I can't
>> >seem to create a pointer in CWndThread Ijust created that will point back
>to
>> >the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.  The
>> >FtpThread gets started and then starts the ScanRecvThread and when that
>> >happens the AfxBeginThread returns the pointer to ScanRecvThred.  Though
>I
>> >start the ScanRecvThread suspended and initialize its variables, BUT I
>can't
>> >seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

>> >So This is how I would start (pseudo)
>> >p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
>> >p_ScanRecvThread->p_FtpThread = this;

>> >But I can't seem to create a variable of type p_FtpThread in the new
>class
>> >even if I include the header at the top?  Is there a better way todo
>this?

>> >Thanks
>> >Darren King

>> Joseph M. Newcomer [MVP]

>> Web: http://www3.pgh.net/~newcomer
>> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sun, 27 Apr 2003 03:00:00 GMT  
 Starting a UI Thread from a UI Thread.
Well as it turns out this Method is back on.  I was able to use the Socket
in between threads and it WORKED!?  Without using Detach and Attach.  It
could have been my usuage was so fundamental trying to hold onto som later
Unix compatibility that it was OK.  I tried the method with a Class Member
Function worker thread.  Then I made the Class member function worker thread
static and it still complained about the variables it used...  I went back
to the original derived Thread Class and even though I put the #include I
could not create a pointer to the first Thread Object.  I even tried
CWndThread *p_mFtpThread.  After I came to work today.  I realized
something.  There is no Class CWndThread.  Its CWinThread.  I felt stupid.
Stilll I can't understand why I couldn't just create pointer to the object
with its own class as by putting it at the top of each thread that will
point back to that thread that created it.  I just put at the top of the
other threads #include "FtpThread.h"

But when I tried todo this.

FtpThread *m_pFtpThread;  It would {*filter*}with the usually "non recognized"
type of thing.  No matter the problem is solved with a less acurate but
workable solution, by simply putting.

CWinThread *m_pFtpThread;

Darren King



Quote:
> Sounds like you're missing some minor C/C++ point. Given that it is a
> pointer variable, you can always add the declaration in the header
> file that gets the error:
> class CMySubUIThread;
> so that any use of CMySubUIThread * is properly resolved. The only
> time I ever get this error is if I forget either that declaration or
> the #include.
> joe



> >Oh your right about the socket.  Hmmm..  I'm not sure if that will be a
> >problem though cause of the way the Socket will work in the Thread, I'll
> >have to try it.  What I mean is that when I try to create a pointer
variable
> >that is the type of the UIThread inside a UIThread it just simply says
> >Missing Storage Class or Type Specifiers.  Even though I have an include
for
> >the Class at the top.

> >Darren King



> >> Explain more what you mean by not being able to "create a variable".
> >> What happens? Compile errors? Runtime ASSERTS? (Remember that
> >> cross-thread operations on CWnd objects and CSocket objects don't
> >> work, although you are free to access your own data cross-thread).
> >> joe



> >> >I'm working with MFC more and more all the time.  Meaning to say the
> >program
> >> >started out Win32 only, but now its got all kinds of MFC in it, so...
I
> >> >created a UI thread with the ClassWizard and derived from CWndThread
> >(Thats
> >> >the name right?) and then created a thread using that New Class with
> >> >AfxBeginThread.  All goes great.  Now I created another Class same way
> >using
> >> >ClassWizard and deriving from CWndThread.  Now I want to give the
Threads
> >> >access to each others variables.  Purly for reading data.  Though I
can't
> >> >seem to create a pointer in CWndThread Ijust created that will point
back
> >to
> >> >the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.
The
> >> >FtpThread gets started and then starts the ScanRecvThread and when
that
> >> >happens the AfxBeginThread returns the pointer to ScanRecvThred.
Though
> >I
> >> >start the ScanRecvThread suspended and initialize its variables, BUT I
> >can't
> >> >seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

> >> >So This is how I would start (pseudo)
> >> >p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
> >> >p_ScanRecvThread->p_FtpThread = this;

> >> >But I can't seem to create a variable of type p_FtpThread in the new
> >class
> >> >even if I include the header at the top?  Is there a better way todo
> >this?

> >> >Thanks
> >> >Darren King

> >> Joseph M. Newcomer [MVP]

> >> Web: http://www.*-*-*.com/ ~newcomer
> >> MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm

> Joseph M. Newcomer [MVP]

> Web: http://www.*-*-*.com/ ~newcomer
> MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm



Sun, 27 Apr 2003 03:00:00 GMT  
 Starting a UI Thread from a UI Thread.
Yes, you must call a static method as the thread procedure, but you
can't access member variables of the class from a static member
function (except for static member variables). See my essay on worker
threads on my MVP Tips site where I explain how to deal with this. I'm
not sure, though, what you mean by "putting it at the top of each
thread". Check out my essay, which might clarify things.
                        joe



Quote:
>Well as it turns out this Method is back on.  I was able to use the Socket
>in between threads and it WORKED!?  Without using Detach and Attach.  It
>could have been my usuage was so fundamental trying to hold onto som later
>Unix compatibility that it was OK.  I tried the method with a Class Member
>Function worker thread.  Then I made the Class member function worker thread
>static and it still complained about the variables it used...  I went back
>to the original derived Thread Class and even though I put the #include I
>could not create a pointer to the first Thread Object.  I even tried
>CWndThread *p_mFtpThread.  After I came to work today.  I realized
>something.  There is no Class CWndThread.  Its CWinThread.  I felt stupid.
>Stilll I can't understand why I couldn't just create pointer to the object
>with its own class as by putting it at the top of each thread that will
>point back to that thread that created it.  I just put at the top of the
>other threads #include "FtpThread.h"

>But when I tried todo this.

>FtpThread *m_pFtpThread;  It would {*filter*}with the usually "non recognized"
>type of thing.  No matter the problem is solved with a less acurate but
>workable solution, by simply putting.

>CWinThread *m_pFtpThread;

>Darren King



>> Sounds like you're missing some minor C/C++ point. Given that it is a
>> pointer variable, you can always add the declaration in the header
>> file that gets the error:
>> class CMySubUIThread;
>> so that any use of CMySubUIThread * is properly resolved. The only
>> time I ever get this error is if I forget either that declaration or
>> the #include.
>> joe



>> >Oh your right about the socket.  Hmmm..  I'm not sure if that will be a
>> >problem though cause of the way the Socket will work in the Thread, I'll
>> >have to try it.  What I mean is that when I try to create a pointer
>variable
>> >that is the type of the UIThread inside a UIThread it just simply says
>> >Missing Storage Class or Type Specifiers.  Even though I have an include
>for
>> >the Class at the top.

>> >Darren King



>> >> Explain more what you mean by not being able to "create a variable".
>> >> What happens? Compile errors? Runtime ASSERTS? (Remember that
>> >> cross-thread operations on CWnd objects and CSocket objects don't
>> >> work, although you are free to access your own data cross-thread).
>> >> joe



>> >> >I'm working with MFC more and more all the time.  Meaning to say the
>> >program
>> >> >started out Win32 only, but now its got all kinds of MFC in it, so...
>I
>> >> >created a UI thread with the ClassWizard and derived from CWndThread
>> >(Thats
>> >> >the name right?) and then created a thread using that New Class with
>> >> >AfxBeginThread.  All goes great.  Now I created another Class same way
>> >using
>> >> >ClassWizard and deriving from CWndThread.  Now I want to give the
>Threads
>> >> >access to each others variables.  Purly for reading data.  Though I
>can't
>> >> >seem to create a pointer in CWndThread Ijust created that will point
>back
>> >to
>> >> >the first Funtion.  IE.  I have my FtpThread and the ScanRecvThread.
>The
>> >> >FtpThread gets started and then starts the ScanRecvThread and when
>that
>> >> >happens the AfxBeginThread returns the pointer to ScanRecvThred.
>Though
>> >I
>> >> >start the ScanRecvThread suspended and initialize its variables, BUT I
>> >can't
>> >> >seem to make a instance FtpThread *p_FtpThread in the ScanRecvThread.

>> >> >So This is how I would start (pseudo)
>> >> >p_ScanRecvThread = AfxBeginThread ScanRecvThread supended
>> >> >p_ScanRecvThread->p_FtpThread = this;

>> >> >But I can't seem to create a variable of type p_FtpThread in the new
>> >class
>> >> >even if I include the header at the top?  Is there a better way todo
>> >this?

>> >> >Thanks
>> >> >Darren King

>> >> Joseph M. Newcomer [MVP]

>> >> Web: http://www.*-*-*.com/ ~newcomer
>> >> MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm

>> Joseph M. Newcomer [MVP]

>> Web: http://www.*-*-*.com/ ~newcomer
>> MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm

Joseph M. Newcomer [MVP]

Web: http://www.*-*-*.com/ ~newcomer
MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm


Mon, 28 Apr 2003 14:32:35 GMT  
 
 [ 7 post ] 

 Relevant Pages 

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

2. Doubt in dialog based threads in linux (UI threading)

3. Doubt in dialog based threads in linux (UI threading)

4. UI Thread better than Worker thread for speed?

5. Awakening the UI thread from another thread in a Windows Form application

6. worker thread to ui thread

7. Is it possible for one (UI) thread to Peek into another (UI) threads message queue ?

8. Threads and UI controls

9. Threads and the UI

10. Multi-Threaded UI problem involving Asynch Sockets

11. UI thread and activex control

12. UI Thread from dialog based application

 

 
Powered by phpBB® Forum Software