Thanks,
Nathan Stokes
Research Engineer
System Technology Center
Syracuse Research Corporation
6225 Running Ridge Rd
North Syracuse, NY 13212
sto...@syrres.com
315.452.8125
---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
For additional commands, e-mail: wx-use...@lists.wxwidgets.org
In wxWindows all event handlig occurs always in main thread.
Regards,
Łukasz
I ended up deriving just from wxThread and creating a different class that
derived from wxEvtHandler.
Kevin
----- Original Message -----
From: "Nathan Stokes" <sto...@syrres.com>
To: "Wx-Users" <wx-u...@lists.wxwidgets.org>
Sent: Tuesday, April 13, 2004 9:31 AM
Subject: wxSocket Event Notification in a Thread
> I am working on an application using wxWindows on MSW, with the MFC
> compatibility turned on so as to get Direct Draw support. I am trying to
> set up a thread to monitor a wxSocket for incoming data using a
> wxSocketEvent. My thread class inherits wxEventHandler and wxThread. I
> declare an event table, register the event with wxSocket. My event
handling
> function is called when I get incoming data, but the context is wrong.
The
> object context of the handler when it is called is not the same context as
> the thread that created the socket. Are event handlers thread safe when
> implemented as I have?
>
> Thanks,
>
> Nathan Stokes
I use a similar trick in my ThreadHandler code to process events in a
thread:
The basica idea is to override wxEvtHandler::ProcessEvent in the
thread-based event handler class. The implementation pushes the event
onto a threadsafe message queue. The thread main loop can be written to
consume events as they become available in the queue, calling
wxEvtHandler::ProcessEvent on each one.
So an event that gets posted to the thread-based event handler class,
either through wxPostEvent or the ProcessEvent event method, gets added
to your message queue by the main thread, then dispatched to the correct
event handler in the handler's thread.
My first implementations used multiple inheritance, and that strategy
seemed to work ok. But now that I am using thread pools I, I just derive
my ThreadHandler class from wxEvtHandler.
Hope that helps,
Aj