Mein Thread schliesst sich nicht mehr
-
Das Problem das ich mit der Datenbank hatte habe ich gelöst indem ich alle DB Zugriffe aus dem Thread ausgelagert habe.
Nun bleibt aber aus irgendeinen Grund der Thread offen wenn das Programm beendet wird.Mein Thread:
bool stop = false; CAutofinderDlg * parent =(CAutofinderDlg *) pParam; parent->sucht=true; CString sql ="Update Links set Color='160060060' Where Color= '255000000'"; SendMessage(parent->GetSafeHwnd(),WM_DBEXECUTE,0,(long)&sql);//Führt den SQL String aus round++; int c =0; CWebGrab Grab; round2 =0; Field_Searcher fs;//Eine Klasse die einen Text nach Vorgaben aus der DB zerlegt und das Ergebnis in der DB speichert Copy_Fieldsearcher(&fs,&parent->feldsucher);//Kopieren der Arrays mit Daten aus der DB in das Field_SearcherObject des Threads int bin = parent->AA.GetSize(); CSingleLock lock2(&agenten_lock, true); for (int x =0;x< parent->AA.GetSize();x++) { if(!(WaitForSingleObject(g_EventKill,0)==WAIT_TIMEOUT)) { stop = true; break; } if(parent->AA[x] != NULL&&parent->AA[x]->aktiv) { CString Url = parent->AA[x]->Url; parent->SetDlgItemText(IDC_CSPA,"Aktueller Agent:" + parent->AA[x]->Name); char buffer[6]; _itoa(parent->AA[x]->Ag_Nr,buffer,10); lock2.Unlock(); SetConfig("LastSp",buffer); lock2.Lock(); if(parent->suche_1 == true) { fs.Add_Fields(1,parent->AA[x]->Sp_Nr,parent->AA[x]->Url,&lock2,parent->AA[x]->use_empty_ez); SendMessage(parent->GetSafeHwnd(),WM_FILLLIST,0,0);//Füllt ein ListCtrl mit Daten aus der DB } if(parent->suche_2 == true) { fs.Add_Fields(2,parent->AA[x]->Sp_Nr,parent->AA[x]->Url_2,&lock2,parent->AA[x]->use_empty_ez); SendMessage(parent->GetSafeHwnd(),WM_FILLLIST,0,0); } } } if(!stop) { parent->sucht = false; parent->SetTimer(TIMER1,600,NULL); } else { parent->KillTimer(TIMER1); parent->FindAutos_stop = true; } return FALSE; }OnDestroy:
g_EventKill.SetEvent(); Sleep(420000); DB.force_close(); CHMXDialog::OnDestroy();
-
Ich habe Sleep und das Schliessen der Datenbank rausgenommen und jetzt läuft es.