title: wxWidgets CallAfter waking main UI thread on macOS?
body: <p>I am getting "UI API called from background thread" errors under wxWidgets master from GitHub under macOS. </p>
  
  <pre><code>UI API called from background thread Group
  file:///DeveloperLibs/wxWidgets-3.1.3/src/osx/cocoa/evtloop.mm: runtime: UI API called from background thread: -[NSApplication postEvent:atStart:] must be used from main thread only
  
  #0  0x00000001004e5908 in wxGUIEventLoop::WakeUp() at /DeveloperLibs/wxWidgets-3.1.3/src/osx/cocoa/evtloop.mm:390
  #1  0x00000001004651fd in wxApp::WakeUpIdle() at /DeveloperLibs/wxWidgets-3.1.3/src/osx/carbon/app.cpp:439
  #2  0x00000001001d0cf7 in wxWakeUpIdle() at /DeveloperLibs/wxWidgets-3.1.3/src/common/appbase.cpp:1108
  #3  0x00000001003a6a03 in wxEvtHandler::QueueEvent(wxEvent*) at /DeveloperLibs/wxWidgets-3.1.3/src/common/event.cpp:1318
  #4  0x000000010017a09c in void wxEvtHandler::CallAfter&lt;myPanel::Finish()::$_1&gt;(myPanel::Finish()::$_1 const&amp;) at /DeveloperLibs/wxWidgets-3.1.3/include/wx/event.h:3668
  #5  0x0000000100179fba in myPanel::Finish() at /Volumes/Macintosh HD04/Users/rich/Projects/thing/myPanel.cpp:88
  </code></pre>
  
  <p>.... lines beneath here are just thread/_pthread_start stuff that isn't relevant.</p>
  
  <p>Inside <code>myPanel::Finish()</code> (which is called by the thread when it finishes), I am using:</p>
  
  <pre><code>void myPanel::Finish()
  {
    this-&gt;GetEventHandler()-&gt;CallAfter([this]()
    {
      stopButton-&gt;Disable();
      GoToResultsPanel();
    });
  }
  </code></pre>
  
  <p>The issue is not the code in my lambda but the actual CallAfter call since it calls <code>wxWakeUpIdle()</code>, which then ends up in <code>wxApp::WakeUpIdle()</code>, which ends up in <code>wxGUIEventLoop::WakeUp()</code>, calling <code>[NSApp postEvent:event atStart:FALSE];</code></p>
  
  <p>In this way my background thread is waking the UI thread. The documentation for <code>wxEvtHandler::CallAfter</code> states:</p>
  
  <p><em>Notice that it is safe to use CallAfter() from other, non-GUI, threads, but that the method will be always called in the main, GUI, thread context.</em></p>
  
  <p>This does not seem to be the case here? What am I doing wrong?</p>
  
  <p>EDIT: BTW This is under macOS Catalina. Under macOS Sierra and with wxWidgets 3.1.3 I do not get a runtime warning about the identical code. The evtloop.mm code is identical but produces no warnings under this older macOS!</p>