Multi threading
-
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(); }
-
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(); }
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)
-
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)
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 theUINT CUpdateView::run(LPVOID p)
declare as static? see declaration of 'GetDocument' My declaration isCUpdateDoc* GetDocument();
in CUpdateView Class -
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 theUINT CUpdateView::run(LPVOID p)
declare as static? see declaration of 'GetDocument' My declaration isCUpdateDoc* GetDocument();
in CUpdateView ClassSee 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)
-
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)