Hello,

he timer also starts a thread in which an io_service hosts deadline timer until thread is terminated. so a continuous timer. The boost thread which needs the timer is create from within DLL.

The DLL ExitInstance function is called, when the hosting App. unloads the DLL. The ExitInstance function stops the thread and before timer. But the io_service destruction in my timer never returns, so the app hangs.

This happens NOT, when i am able to call a Dispose Function before ExitInstance is called. However, some application loading my DLL, give not the chance to call this expose function.

Anyone know, how to work around this problem ?

Here is the code of my timer core. It is the thread which restarts the service until thread is stopped. The thread get's stopped by setting _stop flag and setting deadlime timer to 1 ms in future. summary: hangs when within Dll::ExitInstance destructed. Hangs not, if destrcuted before Dll::ExitInstance Thank you

Code:

 

void tcTimerThread::timerLoop(void)

{

_running=true;

_io_service = new boost::asio::io_service;

   
/// create timer
    _pTimer =
new boost::asio::deadline_timer(*_io_service);
   
while(_stop==false)
    {  
        _pTimer->expires_from_now(boost::posix_time::milliseconds(_delay));            
       
/// bind timer event function
        _pTimer->async_wait(boost::bind(&tcTimerThread::timerEvent,
this,boost::asio::placeholders::error));    
       
try
        {
           
if(_stop==false)
            {
               
/// reset async
                _io_service->reset();
               
/// wait for timer event
                _io_service->run();
            }
        }
       
catch(...)
        {
        }
    }
   
try
    {
       _io_service->stop();
       
delete _pTimer;

       /// !! never returns if called within ExitInstance of DLL;returns always is called before ExitInstance of DLL
       
delete _io_service;
    }
   
catch(...)
    {
    }
    _running=
false;

}