calling CDatabase in a worker thread
-
hi all, i used CWinthread created a worker for monitoring a port. in that thread, i need to connect to database. so, i hope to connect the database at that class and execute sql in the worker thread. but, i can't do so. seems that the worker thread can't access that object. here is the code, pls give me some ideas!!! CDatabase db; class CAN { CWinThread abc; static int workerthread; //static CDatabase db; } i tried both setting the CDatabase as global or static. both are not able to access by workerthread. do you have any idea letting workerthread using out thread's object? thanks, jim
-
hi all, i used CWinthread created a worker for monitoring a port. in that thread, i need to connect to database. so, i hope to connect the database at that class and execute sql in the worker thread. but, i can't do so. seems that the worker thread can't access that object. here is the code, pls give me some ideas!!! CDatabase db; class CAN { CWinThread abc; static int workerthread; //static CDatabase db; } i tried both setting the CDatabase as global or static. both are not able to access by workerthread. do you have any idea letting workerthread using out thread's object? thanks, jim
*.h -------------------------------------- class CAutoObList : public CObject { public: CAutoObList() { size = 10; p = new int[size]; for(int i=0; iSuspendThread(); delete pThread; pThread = NULL; } } void testThread(); }; *.cpp -------------------------------------------------------- CAutoObList autoList; UINT CAutoObListThread(LPVOID object) { // A *pA = ((A*) object); for(;;) { autoList.Output(); Sleep( 2000 ); } return 0; } void A::testThread() { if( pThread == NULL ) pThread = AfxBeginThread(CAutoObListThread, this,THREAD_PRIORITY_HIGHEST); } output: ----------------- 0: 0 1: 1 ... 9: 9 hope can help!