2
後來是我的程序,但它不像我期望的那樣工作。我希望主窗口程序調用函數「MyDllIniSys」在dll中,讓dll的渲染窗口大概爲32微秒,直到主窗口程序設置「bIAutoRender」不等於1. 所以我希望函數「MyDllIniSys」啓動線程,並立即返回。 但是,在我所做的,該程序不會工作,如果線程開始,它將永遠不會返回。 我怎樣才能得到它,有人請。幫幫我。 非常感謝如何在後臺使用多線程提升線程
static void renderOneFrame(const boost::system::error_code& /*e*/,
boost::asio::deadline_timer* t, int* iNeedAutoRender)
{
//call Who use this DLL, let it refresh the window
if(OnRefreshEvent)
{
OnRefreshEvent();
}
if(*iNeedAutoRender == 1)
{
t->expires_at(t->expires_at() + boost::posix_time::microseconds(iIRenderMicroSenconds));
t->async_wait(boost::bind(renderOneFrame,
boost::asio::placeholders::error, t, iNeedAutoRender));
}
}
EXTERN_C MYDLLAPI INT MyDllIniSys(INT WindowWidth,INT WindowHeight)
{
COgreRenderLoader myLoader;
myLoader.IniOgre(externalWindowHandle,WindowWidth,WindowHeight);
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::microseconds(iIRenderMicroSenconds));
t.async_wait(boost::bind(renderOneFrame,
boost::asio::placeholders::error, &t,&bIAutoRender));
boost::thread thread1(boost::bind(&boost::asio::io_service::run, &io));
//io.run();
thread1.join();
//thread1.start_thread();
return 1;
}