Subject | IB & Threads |
---|---|
Author | Behnke@hbg.dpa.de |
Post date | 2001-10-22T07:58:16Z |
Dear Members,
sorry for my long descripton of my problem
I have two threads:
tdbindexlist_SpeicherUebersicht
tdbindexlist_zurBearbeitung
Every thread has his own:
ib_Connection.reset(new TIB_Connection(NULL));
ib_Transaction.reset(new TIB_Transaction(NULL));
ib_Query.reset(new TIB_Query(NULL));
ib_DataSource.reset(new TIB_DataSource(NULL));
ib_Cursor.reset(new TIB_Cursor(NULL));^
which will be created in the constructor of the object
__fastcall TTDbIndexList::TTDbIndexList(bool CreateSuspended,
AnsiString strDataBase,
HWND hMain,
int who,
long int MaxCount
) : TThread(true)
{
FreeOnTerminate = true;
caller = who;
IndexList.reset(new TList);
Temp_IndexList.reset(new TList);
DB_Server.reset(new TTIB_Server()); // here the tread get his own
DB-Connection !
bool result = DB_Server->Connect(strDataBase);
restorecounter = MaxCount;
hMainForm = hMain;
IB_Events->OnEventAlert = EventAlert;
if (result )
IB_Events->RegisterEvents();
}
in the Execute methode of the threads
a list will be filled (FillList(restorecounter);
with the latest incoming news:
void __fastcall TTDbIndexList::Execute()
{
while (!Terminated)
{
FillList(restorecounter);
// inform the main
PostMessage(hMainForm,WM_INDEXLIST_CHANGE,0,caller);
Suspend();
}
}
long int TTDbIndexList::FillList(const long int count) // amount of
the showing elements
{
int c=0;
try {
// might be we lost the connection
if (!DB_Server->Connected())
DB_Server->Connect();
AnsiString SQL = "SELECT
MldIndex,FolderImage,SelectedImage,StateImage, GUID_BASIS,
GUID_CHANGE FROM STAR_Document where Create_Date <
'tomorrow'";// ORDER BY Create_Time DESC";
DB_Server->Cursor()->SQL->Clear();
DB_Server->Cursor()->SQL->Add(SQL);
DB_Server->Transaction()->StartTransaction();
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
trace_msg ("%s\t%s","TDBIndexListThread: ","before prep");
DB_Server->Cursor()->Prepare();
// in the case of using the IB-Server on the same pc the program
// don't step to here !!!!!!!!!!!!!!!!!!!!!!!!!!
// but there is no exception !!!!
trace_msg ("%s\t%s","TDBIndexListThread: ","after prep");
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DB_Server->Cursor()->Open();
Temp_IndexList->Clear();
while ((!DB_Server->Cursor()->Eof) && (c<count))
{// fill the list with amount of count
TIndexItem* IndexItem = new TIndexItem;
IndexItem->Index = DB_Server->Cursor()->FieldByName
("MldIndex")->AsString;
IndexItem->GUID_BASIS = DB_Server->Cursor()->FieldByName
("GUID_BASIS")->AsString;
IndexItem->GUID_CHANGED = DB_Server->Cursor()->FieldByName
("GUID_CHANGE")->AsString;
IndexItem->FolderImage = DB_Server->Cursor()->FieldByName
("FOLDERIMAGE")->AsInteger;
IndexItem->SelectedImage = DB_Server->Cursor()->FieldByName
("SELECTEDIMAGE")->AsInteger;
IndexItem->StateImage = DB_Server->Cursor()->FieldByName
("STATEIMAGE")->AsInteger;
Temp_IndexList->Add(IndexItem);
DB_Server->Cursor()->Next();
c++;
}
}
catch (EIB_StatementError& e)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e.Message.c_str());
}
catch (EIB_Error& e2)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e2.Message.c_str
());
}
catch (EIBO_ISCError& e3)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e3.Message.c_str
());
}
catch (EDatabaseError& e4)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e4.Message.c_str
());
}
catch (...)
{
trace_msg ("%s\t%s","TDBIndexListThread:","unknown DB-Error");
}
DB_Server->Cursor()->Close();
DB_Server->Transaction()->Commit();
return c;
}
If i wake up the threads
tdbindexlist_SpeicherUebersicht->Resume();
tdbindexlist_zurBearbeitung->Resume();
the code above runs without any problems if the IB-Server is located
on a seperate PC.
If the IB-Server is on the same PC it works only if i start one
thread wait for finish and then i start the second
Any ideas ?!
Best regards from Germany
Gerhard Behnke
P.S. i use WIN 2000 256 MByte RAM
IB-Server WI-V6.0.1
sorry for my long descripton of my problem
I have two threads:
tdbindexlist_SpeicherUebersicht
tdbindexlist_zurBearbeitung
Every thread has his own:
ib_Connection.reset(new TIB_Connection(NULL));
ib_Transaction.reset(new TIB_Transaction(NULL));
ib_Query.reset(new TIB_Query(NULL));
ib_DataSource.reset(new TIB_DataSource(NULL));
ib_Cursor.reset(new TIB_Cursor(NULL));^
which will be created in the constructor of the object
__fastcall TTDbIndexList::TTDbIndexList(bool CreateSuspended,
AnsiString strDataBase,
HWND hMain,
int who,
long int MaxCount
) : TThread(true)
{
FreeOnTerminate = true;
caller = who;
IndexList.reset(new TList);
Temp_IndexList.reset(new TList);
DB_Server.reset(new TTIB_Server()); // here the tread get his own
DB-Connection !
bool result = DB_Server->Connect(strDataBase);
restorecounter = MaxCount;
hMainForm = hMain;
IB_Events->OnEventAlert = EventAlert;
if (result )
IB_Events->RegisterEvents();
}
in the Execute methode of the threads
a list will be filled (FillList(restorecounter);
with the latest incoming news:
void __fastcall TTDbIndexList::Execute()
{
while (!Terminated)
{
FillList(restorecounter);
// inform the main
PostMessage(hMainForm,WM_INDEXLIST_CHANGE,0,caller);
Suspend();
}
}
long int TTDbIndexList::FillList(const long int count) // amount of
the showing elements
{
int c=0;
try {
// might be we lost the connection
if (!DB_Server->Connected())
DB_Server->Connect();
AnsiString SQL = "SELECT
MldIndex,FolderImage,SelectedImage,StateImage, GUID_BASIS,
GUID_CHANGE FROM STAR_Document where Create_Date <
'tomorrow'";// ORDER BY Create_Time DESC";
DB_Server->Cursor()->SQL->Clear();
DB_Server->Cursor()->SQL->Add(SQL);
DB_Server->Transaction()->StartTransaction();
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
trace_msg ("%s\t%s","TDBIndexListThread: ","before prep");
DB_Server->Cursor()->Prepare();
// in the case of using the IB-Server on the same pc the program
// don't step to here !!!!!!!!!!!!!!!!!!!!!!!!!!
// but there is no exception !!!!
trace_msg ("%s\t%s","TDBIndexListThread: ","after prep");
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DB_Server->Cursor()->Open();
Temp_IndexList->Clear();
while ((!DB_Server->Cursor()->Eof) && (c<count))
{// fill the list with amount of count
TIndexItem* IndexItem = new TIndexItem;
IndexItem->Index = DB_Server->Cursor()->FieldByName
("MldIndex")->AsString;
IndexItem->GUID_BASIS = DB_Server->Cursor()->FieldByName
("GUID_BASIS")->AsString;
IndexItem->GUID_CHANGED = DB_Server->Cursor()->FieldByName
("GUID_CHANGE")->AsString;
IndexItem->FolderImage = DB_Server->Cursor()->FieldByName
("FOLDERIMAGE")->AsInteger;
IndexItem->SelectedImage = DB_Server->Cursor()->FieldByName
("SELECTEDIMAGE")->AsInteger;
IndexItem->StateImage = DB_Server->Cursor()->FieldByName
("STATEIMAGE")->AsInteger;
Temp_IndexList->Add(IndexItem);
DB_Server->Cursor()->Next();
c++;
}
}
catch (EIB_StatementError& e)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e.Message.c_str());
}
catch (EIB_Error& e2)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e2.Message.c_str
());
}
catch (EIBO_ISCError& e3)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e3.Message.c_str
());
}
catch (EDatabaseError& e4)
{
trace_msg ("%s\t%s","TDBIndexListThread: ",e4.Message.c_str
());
}
catch (...)
{
trace_msg ("%s\t%s","TDBIndexListThread:","unknown DB-Error");
}
DB_Server->Cursor()->Close();
DB_Server->Transaction()->Commit();
return c;
}
If i wake up the threads
tdbindexlist_SpeicherUebersicht->Resume();
tdbindexlist_zurBearbeitung->Resume();
the code above runs without any problems if the IB-Server is located
on a seperate PC.
If the IB-Server is on the same PC it works only if i start one
thread wait for finish and then i start the second
Any ideas ?!
Best regards from Germany
Gerhard Behnke
P.S. i use WIN 2000 256 MByte RAM
IB-Server WI-V6.0.1