Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. calling CDatabase in a worker thread

calling CDatabase in a worker thread

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chaze
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • C chaze

      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

      W Offline
      W Offline
      wangyiming
      wrote on last edited by
      #2

      *.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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups