Hang in RunMessageLoop | win32 C++

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Re: Hang in RunMessageLoop | win32 C++

Postby ndesktop » Fri Mar 15, 2024 10:06 am

Normally it should work.

Can you use a lousy timer (for testing) to perform a pooling on the opened/closed browsers ?
Saying your app is keeping count of opened browsers in a browsers_count variable, simply do InterlockedIncrement on browsers_count in client handler OnAfterCreated, InterlockedDecrement on browsers_count in OnBeforeClose, and when you want to do quit it will be something like in this crude Windows pseudocode

Code: Select all
void ClientHandler::OnAfterCreated() {
...
  InterlockedIncrement(&App::browsers_count);
}

void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
...
  InterlockedDecrement(&App::browsers_count);
}

void App::Quit() {
... instead of CefQuitMessageLoop
  quit_timer_id = CreateTimer( ... ); // or a self-rearming CreateWaitableTimer if you don't process WM_TIMER
...
}

void App::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
  if (msg == WM_TIMER) {
    if (wp == quit_timer_id) {
        if (InterlockedCompareExchange(&App::browsers_count, 0, 0) == 0) {
           // done, browsers_count decreased to 0
           PostMessage(hwnd, USER_WM_CLOSE, 0, 0); // define a USER_WM_CLOSE = WM_USER + 100 or so
        }
    }
  }
...
  else if (msg == USER_WM_CLOSE) {
    CefQuitMessageLoop();
    return 0;
  }
  ...
  ... DefWindowProc/CallWindowProc if subclass etc
}
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Previous

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 205 guests