Hi worker thread should look a bit like this.
.
void WorkerThread( boost::shared_ptr< boost::asio::io_service > &io_service )
{
// std::stringstream ss;
// ss << "[" << boost::this_thread::get_id() << "] Thread Start";
// global_stream_lock.lock();
//send the data to the client list box
//SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
//std::cout << "[" << boost::this_thread::get_id()
// << "] Thread Start" << std::endl;
//global_stream_lock.unlock();
while( true )
{
//may not need this the io_service will return and the thread will stop
if(ForceStop)
break;
try
{
boost::system::error_code ec;
io_service->run( ec );//it will wait in here calling io_service->stop(); will make this return
if( ec )
{
//ss.str("");
//ss.clear();
//ss << "[" << boost::this_thread::get_id() << "] Error: " << ec.message();
//global_stream_lock.lock();
//send the data to the client list box
//SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
// std::cout << "[" << boost::this_thread::get_id()
// << "] Error: " << ec << std::endl;
// global_stream_lock.unlock();
//Sleep(10000);
}
//MessageBox(NULL,"io_service Run Returned","Thread will End Now",MB_OK);
break;
}
catch( std::exception & ex )
{
// ss.str("");
// ss.clear();
// ss << "[" << boost::this_thread::get_id() << "] Exception: " << ex.what();
// global_stream_lock.lock();
//send the data to the client list box
// SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
MessageBox(NULL, ex.what(),"Thread Exception Catched",MB_OK);
//std::cout << "[" << boost::this_thread::get_id()
// << "] Exception: " << ex.what() << std::endl;
// global_stream_lock.unlock();
}
}
//MessageBox(NULL,"Thread End","Thread End",MB_OK);
}//end WorkerThread
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
with out the worker thread io_services will run until the connect call and then there will be no work to do so it quits.
try boost::shared_ptr<cSession> Session;
Refresher.