Calling on UI thread

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.

Calling on UI thread

Postby artelogic » Thu Mar 03, 2011 8:19 am

A lot of methods of browser or frame shall only be called on the UI thread.
Assuming CEF is initialized multi-threaded, am I right, that the CEF UI thread is different from the applications main thread (which is mostly the app's UI thread)?

Assuming that, how can I call, eg., the frame's get_source on CEF's UI thread, since something like that is mostly intended by a user who clicks somewhere, which is handled in the app's main thread?
Code: Select all
  // Returns this frame's HTML source as a string. This function should only be
  // called on the UI thread.
  // The resulting string must be freed by calling cef_string_userfree_free().
  cef_string_userfree_t (CEF_CALLBACK *get_source)(struct _cef_frame_t* self);
artelogic
Newbie
 
Posts: 2
Joined: Thu Mar 03, 2011 8:03 am

Re: Calling on UI thread

Postby magreenblatt » Thu Mar 03, 2011 9:45 am

Assuming CEF is initialized multi-threaded, am I right, that the CEF UI thread is different from the applications main thread (which is mostly the app's UI thread)?

Correct.

how can I call, eg., the frame's get_source on CEF's UI thread

Use the CefPostTask (cef_post_task) function to execute the get_source method on the UI thread. If you're using the C API you will need to create your own structure extending cef_task_t. If you're using the C++ API you can use the NewCefRunnableMethod and/or NewCefRunnableFunction templates. See the cefclient application for examples using the C++ API.

Once you've executed the method on the UI thread you can post the data back to your application thread using whatever method is most appropriate for your application. For example, the cefclient application uses PostMessage with WM_COMMAND.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 91 guests