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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multi threading

Multi threading

Scheduled Pinned Locked Moved C / C++ / MFC
databasec++helpannouncementlearning
5 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.
  • D Offline
    D Offline
    dreamerzz
    wrote on last edited by
    #1

    Hi, Currently i am working on single document interface MFC to create a small update program to the database to change the values store in the fields. However, in order to let the program run "automatically", i have to used thread. But I know nuts about threading. I have attached the main part of the updating of the program below. pls kindly help..I have read up on books about C++ on the thread function. the book says, to create and start, i have to use AfxBeginThread and have some arguements inside. and a function UINT MyThreadFunction(LPVOID pParam). Really need help on this as its very urgent to me... Thanks a million. void CUpdateView::OnUpdatedb() { // TODO: Add your control notification handler code here double propa_update = 0.814; double resp_update = 0.205; double link_update = 1.19; //get a pointer to the recordset CUpdateDoc* pDoc = GetDocument(); UseRecordset* pUseRecordset = &pDoc->m_UseRecordset; do { //Allows the current record to be edited pUseRecordset->Edit(); //increment in the values from the database pUseRecordset->m_propatime = pUseRecordset->m_propatime*propa_update; pUseRecordset->m_respondtime = pUseRecordset->m_respondtime*resp_update; pUseRecordset->m_link = pUseRecordset->m_link*link_update; //Saves the current changes to the database pUseRecordset->Update(); //Reruns the current SQL query to refresh the recordset pUseRecordset->Requery(); //Update the form UpdateData(true); }while(check_exit!=0); } void CUpdateView::OnExit() { check_exit=0; OnExit(); }

    D 1 Reply Last reply
    0
    • D dreamerzz

      Hi, Currently i am working on single document interface MFC to create a small update program to the database to change the values store in the fields. However, in order to let the program run "automatically", i have to used thread. But I know nuts about threading. I have attached the main part of the updating of the program below. pls kindly help..I have read up on books about C++ on the thread function. the book says, to create and start, i have to use AfxBeginThread and have some arguements inside. and a function UINT MyThreadFunction(LPVOID pParam). Really need help on this as its very urgent to me... Thanks a million. void CUpdateView::OnUpdatedb() { // TODO: Add your control notification handler code here double propa_update = 0.814; double resp_update = 0.205; double link_update = 1.19; //get a pointer to the recordset CUpdateDoc* pDoc = GetDocument(); UseRecordset* pUseRecordset = &pDoc->m_UseRecordset; do { //Allows the current record to be edited pUseRecordset->Edit(); //increment in the values from the database pUseRecordset->m_propatime = pUseRecordset->m_propatime*propa_update; pUseRecordset->m_respondtime = pUseRecordset->m_respondtime*resp_update; pUseRecordset->m_link = pUseRecordset->m_link*link_update; //Saves the current changes to the database pUseRecordset->Update(); //Reruns the current SQL query to refresh the recordset pUseRecordset->Requery(); //Update the form UpdateData(true); }while(check_exit!=0); } void CUpdateView::OnExit() { check_exit=0; OnExit(); }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Sounds like you need a worker thread (i.e., a thread with no message pump). If so, read this article. When it comes time to update the database, create the thread and put your update code in this thread. You might want to periodically post a message back to the main thread indicating progress.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      D 1 Reply Last reply
      0
      • D David Crow

        Sounds like you need a worker thread (i.e., a thread with no message pump). If so, read this article. When it comes time to update the database, create the thread and put your update code in this thread. You might want to periodically post a message back to the main thread indicating progress.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        D Offline
        D Offline
        dreamerzz
        wrote on last edited by
        #3

        Hi, I have read the article that you gave me and have tried implementing the methods into my program.. however, that are still one error which i hope u could help me.. void CUpdateView::OnUpdatedb() { // TODO: Add your control notification handler code here running = true; AfxBeginThread(run, this); } UINT CUpdateView::run(LPVOID p) { CUpdateView* pView = (CUpdateView*)p; pView->run(); double propa_update = 0.814; double resp_update = 0.205; double link_update = 1.19; do { //get a pointer to the recordset **CUpdateDoc* pDoc = GetDocument();** UseRecordset* pUseRecordset = &pDoc->m_UseRecordset; //Allows the current record to be edited pUseRecordset->Edit(); //increment in the values from the database pUseRecordset->m_propatime = pUseRecordset->m_propatime*propa_update; pUseRecordset->m_respondtime = pUseRecordset->m_respondtime*resp_update; pUseRecordset->m_link = pUseRecordset->m_link*link_update; //Saves the current changes to the database pUseRecordset->Update(); //Reruns the current SQL query to refresh the recordset pUseRecordset->Requery(); }while(check_exit!=0); return 0; } void CUpdateView::OnExit() { running = false; } The part that i have it bold is giving mi the error.. the error message is : 'CUpdateView::GetDocument' : illegal call of non-static member function This problem is it because i have the UINT CUpdateView::run(LPVOID p) declare as static? see declaration of 'GetDocument' My declaration is CUpdateDoc* GetDocument(); in CUpdateView Class

        D 1 Reply Last reply
        0
        • D dreamerzz

          Hi, I have read the article that you gave me and have tried implementing the methods into my program.. however, that are still one error which i hope u could help me.. void CUpdateView::OnUpdatedb() { // TODO: Add your control notification handler code here running = true; AfxBeginThread(run, this); } UINT CUpdateView::run(LPVOID p) { CUpdateView* pView = (CUpdateView*)p; pView->run(); double propa_update = 0.814; double resp_update = 0.205; double link_update = 1.19; do { //get a pointer to the recordset **CUpdateDoc* pDoc = GetDocument();** UseRecordset* pUseRecordset = &pDoc->m_UseRecordset; //Allows the current record to be edited pUseRecordset->Edit(); //increment in the values from the database pUseRecordset->m_propatime = pUseRecordset->m_propatime*propa_update; pUseRecordset->m_respondtime = pUseRecordset->m_respondtime*resp_update; pUseRecordset->m_link = pUseRecordset->m_link*link_update; //Saves the current changes to the database pUseRecordset->Update(); //Reruns the current SQL query to refresh the recordset pUseRecordset->Requery(); }while(check_exit!=0); return 0; } void CUpdateView::OnExit() { running = false; } The part that i have it bold is giving mi the error.. the error message is : 'CUpdateView::GetDocument' : illegal call of non-static member function This problem is it because i have the UINT CUpdateView::run(LPVOID p) declare as static? see declaration of 'GetDocument' My declaration is CUpdateDoc* GetDocument(); in CUpdateView Class

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See if this helps:

          //get a pointer to the recordset
          CUpdateDoc* pDoc = **pView->**GetDocument();

          Keep in mind that what you have will not work if the primary thread is also accessing the document or the recordset.


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          D 1 Reply Last reply
          0
          • D David Crow

            See if this helps:

            //get a pointer to the recordset
            CUpdateDoc* pDoc = **pView->**GetDocument();

            Keep in mind that what you have will not work if the primary thread is also accessing the document or the recordset.


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            D Offline
            D Offline
            dreamerzz
            wrote on last edited by
            #5

            Hi, Thanks for ur help. dReaMerzZ

            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