FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
template<class C , class Functor >
void FB::BrowserHost::ScheduleOnMainThread ( const boost::shared_ptr< C > &  obj,
Functor  func 
) const

Schedule a call to be executed on the main thread.

With this template function a call can be scheduled to run asynchronously on the main thread like so:

try {
boost::shared_ptr<ObjectType> obj(get_object_sharedptr());
host->ScheduleOnMainThread(obj, boost::bind(&ObjectType::method, obj, arg1, arg2));
} catch (const FB::script_error&) {
// The call will throw this exception if the browser is shutting down and it cannot
// be completed.

Note that the first parameter should be a shared_ptr to the object the call is made on; this is then used to create a weak_ptr so that if the object goes away before the call is made the call can fail silently instead of crashing the browser.

objA boost::shared_ptr to the object that must exist when the call is made
funcThe functor to execute on the main thread created with boost::bind
See Also

Definition at line 224 of file CrossThreadCall.h.

225  {
226  boost::shared_lock<boost::shared_mutex> _l(m_xtmutex);
227  CrossThreadCall::asyncCall(shared_from_this(), obj, func);
228  }