Re: [Tnfox-discussion] TnFox application in DLL and threads
Brought to you by:
ned14
From: Niall D. <s_s...@ne...> - 2008-09-16 15:22:13
|
On 15 Sep 2008 at 15:44, Ck wrote: > > If your main thread is a MFC thread, then you'll need to pump the FOX > > message dispatch system manually from within the MFC message loop. > > > How to do this? > Can you give an example? Look at the source for TnFXApp::run() and FXApp::run(). Basically it runs via getNextEvent() and dispatchEvent(). > I think I need to use FXObject... > > struct Data; > class Receiver: public FXObject > { > public: > ... > /** For sync calls. */ > void syncCall(Data *data); > > /** For async calls. */ > long tryHandle (FXObject *sender, FXSelector sel, void *ptr); > } > > For sync call from worker thread I can do: > m_receiver->syncCall(m_data); > > For async: > m_receiver->getEventLoop()->postAsyncMessage(bla bla); > > How to pump Receiver message system from MFC message lopp? See above. If you wish to invoke some synchronous call which isn't threadsafe, you should set up a message handler which receives async messages from other threads and executes the required call. I personally would have it pass a BoundFunctor such that any thread can invoke any function in any other thread arbitrarily. I have an implementation of this actually in Tn but not TnFOX - it wouldn't be hard to port over though. I might add that to the todo list actually. > PS Is this ok, what I write to you personally instead of to maillist? I'd prefer the mailing list so others can search it in the future. HTH, Niall |