Threading and GUI

wxD
torhu
2007-11-05
2013-05-22
  • torhu
    torhu
    2007-11-05

    I want to call gui functions from other threads than the main one.  What's the recommended way of doing that in wxD?

    From reading wxWidgets docs, it seems that either a custom event, or wxCommandEvent, in combination with wxEvtHandler.AddPendingEvent and ProcessEvent is one way to do this.  Does the wxd solution differ much from what the wxWidgets docs say?

    Basically I want to duplicate the functionality of DWT's syncExec and asyncExec functions.  I tried this:

    void syncExec(Object o, void delegate(Object) dg)
    {
        bool isMain = mainThread.isSelf();

        if (isMain) {
            dg(o);
        }
        else synchronized (execMutex) {
            MutexGuiEnter();
            dg(o);
            MutexGuiLeave();
        }
    }

    asyncExec does the same thing, but doesn't block.  I haven't thought this through yet, but I suppose mixing phobos threads with wxThreads isn't such a great idea?

     
    • torhu
      torhu
      2007-11-12

      I'm trying to create a custom event now, but I get 'no match for implicit super() call in constructor'.  wxD's Event class only has one constructor, which looks like this: 'this(IntPtr wxobj)'.  What argument should I give it?

       
    • Mike Wey
      Mike Wey
      2007-11-12

      Normally the pointer to the associated C++ object gets passed to it. I guess when deriving from it you would pass the pointer to the base c++ object. I don't know how to get one for the wxEvent.

       
    • torhu
      torhu
      2007-11-16

      I had a look at Event's source code, and it doesn't seem that custom events are supported yet.  I guess it's a bit too early to try to use wxD for multithreaded apps yet.  I'll have to try out yet another GUI library. :(