I have just started trying to do multithreading and having read Ginny's
paper and numerous posts on the newsgroup, I think I have got it setup
correctly, however when I return or call ExitVOThread from my worker
thread, the whole app exits.
My code is as follows:
METHOD pbRunNow() AS VOID PASCAL CLASS Processes
LOCAL hThread AS PTR
LOCAL dwProcessID AS DWORD
LOCAL nID AS DWORD
BEGIN SEQUENCE
dwProcessID := Val(SELF:oDCsleProcessID:TextValue)
hThread := CreateVOThread(NULL_PTR, 0, ProcessThread(),;
dwProcessID, 0, @nID)
CloseHandle(hThread)
END SEQUENCE
RETURN
FUNCTION ProcessThread(dwProcessID AS DWORD) AS DWORD PASCAL
LOCAL oSQL2Text AS SQL2Text
LOCAL oSQLSelect AS SQLSelect
LOCAL oDBSchedule AS MDbServer
LOCAL cFileName AS STRING
BEGIN SEQUENCE
oDBSchedule := MDbServer{"SCHEDULE", TRUE, FALSE}
oDBSchedule:SetOrder("SCHEDULE1")
oSQL2Text := SQL2Text{}
oDBSchedule:Seek(dwProcessID)
oSQLSelect := SQLSelect{oDBSchedule:FG(#SQL),;
GetAppObject():oSQLConnection}
IF oSQLSelect:Execute()
cFileName := oDBSchedule:FG(#FILENAME)
IF Instr("ddmmyyyy", cFileName)
cFileName := StrTran(cFileName, "ddmmyyyy",;
PadL(NTrim(Day(Today())), 2, "0");
+ PadL(NTrim(Month(Today())), 2, "0");
+ NTrim(Year(Today())))
ELSEIF Instr("ddmmyy", cFileName)
cFileName := StrTran(cFileName, "ddmmyy",;
PadL(NTrim(Day(Today())), 2, "0");
+ PadL(NTrim(Month(Today())), 2, "0");
+ Right(NTrim(Year(Today())), 2))
ENDIF
oSQL2Text:ExportSQL(oSQLSelect, cFileName)
ENDIF
oSQLSelect:FreeStmt(SQL_DROP)
END SEQUENCE
RETURN 0
I have tried putting an ExitVOThread(0) call in before the END SEQUENCE
and it bails out there instead. As I understand it, RETURN will call
ExitVOThread anyway, so I believe this to be the problem.
I have also tried it with a WaitForSingleObject(hThread, INFINITE) in
the pbRunNow method in which case the application pauses until the
process finishes and then bails out.
I'm aware that I might be doing something blatantly wrong as this is my
first attempt at multithreading, but I can't see it!
Thanks in advance for any help or advice,
PhilHalf
So it's now working, but if there are any other parts of the code that
anyone has any suggestions on, especially on any part of the
multithreading, please let me know.
Thanks again,
PhilHalf
I don't recommend the use of ExitVOThread at all because it can leave your
app in an indeterminate state. I'd suggest constructing your logic so worker
functions simply return instead, perhaps by having them check a variable to
see if they should continue or stop.
--
Ginny
"PhilHalf" <phil...@lycos.co.uk> wrote in message
news:1106653978....@c13g2000cwb.googlegroups.com...