2

后部分是我的程序,但它没有按我的预期工作。我希望 dll 中的主窗口程序调用函数“MyDllIniSys”,让 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;
}
4

1 回答 1

0

调用 thread1.join() 将阻塞,直到 thread1 完成执行。将其关闭,您的函数将启动线程并立即返回。

线程将继续,即使 thread1 对象超出范围,正如您从这个问题中看到的那样

于 2013-06-11T21:48:27.280 回答