multithreading - Are you allowed to call assign function for objects on a suspended thread? -
i have project windows service starts thread job, part has been working long time, not part of problem. trying when job starts , ends, should start thread (eventmessenger inherited tthread) send emails notification job has started , ended. know can not have nested threads, think should ok start 1 thread another, belong main process. create thread in suspended mode, uncertain whether ok call assign objects on thread object while suspended.
eventmessenger := teventmessenger.create(true); // true = start suspended eventmessenger.statuscode := astatuscode; eventmessenger.receiver.assign(receiver); eventmessenger.messageoptions.assign(messageoptions); eventmessenger.messagedetails := amessage; eventmessenger.freeonterminate := true; eventmessenger.resume;
the execute teventmessenger sends mail using indy tidsmtp, here part of code
try self.fmessage.from.address := asender; self.fmessage.recipients.emailaddresses := areceiver; self.fmessage.subject := asubject; self.fmessage.body.text := amessage; try self.fsmtp.connect; self.fsmtp.send(self.fmessage); except on e:eidexception begin currenteurekalogoptions.exceptiondialogoptions := []; // don't show dialog box standardeurekanotify(e, exceptaddr()); // save exception file end; end; if self.fsmtp.connected self.fsmtp.disconnect; end;
the first time start thread eventmessenger works fine , sends email job has started. when starts eventmessenger again send mail job has stopped, got stack overflow in ntdll. wonder if assign in suspended mode can mess stack or whether there problem in indy; read case problem if exceptions not masked when mixing managed/unmanaged code, not sure whether has it. note: i'm not using default indy in delphi 2009, has several bugs, i'm running indy10 code downloaded repository in january.
:779e010f ntdll.kiuserexceptiondispatcher + 0xf :77a2878b ; ntdll.dll :779e010f ntdll.kiuserexceptiondispatcher + 0xf :77a2878b ; ntdll.dll :779e010f ntdll.kiuserexceptiondispatcher + 0xf :77a2878b ; ntdll.dll
any 1 got idea problem causes stack overflow or how can catch exception? have wrapped indy send in try/except, guess works main process not threads, added try/except around code in eventmesssenger.execute calls handleexception have implemented following code, service crashes av without entering exceptionhandler.
procedure teventmessenger.dohandleexception; begin if fexception exception begin currenteurekalogoptions.exceptiondialogoptions := []; // don't show dialog box standardeurekanotify(fexception, exceptaddr()); // save exception file end; end; procedure teventmessenger.handleexception; begin fexception := exception(exceptobject); try if not (fexception eabort) synchronize(dohandleexception); fexception := nil; end; end;
to answer question - assign()
work fine while thread suspended. not touching stack, assign()
method of tpersistent
, , delphi objects exist on heap, not stack.
a stack overflow means encountered recursive function call never ended. run code in debugger , @ call stack when overflow occurs, diagnose function getting stuck in recursive loop.
Comments
Post a Comment