BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnTerminate never gets called in COM Server

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
cristian.adrian.pop@gmail
Guest





PostPosted: Thu Jan 06, 2005 2:20 pm    Post subject: OnTerminate never gets called in COM Server Reply with quote



Hi,

I have a IN-PROCESS COM SERVER that creates a thread to do the actual
work. I want to be able to

gracefully terminate the thread and send the event back to the client.

For that the server exposes a Terminate function for signaling the
thread that it has to terminate. The

client implements the necessary eventsink.

The problem is that the thread never executes the OnTerminate event.

Using a OUT-OF-PROCESS SERVER all this works fine.

Actually, the thread object executes DoTerminate method but it never
arrives to execute

Here's the snipet:

________________________
!!!!!!!!!!!!!!!!!!!! in the classes unit:

function ThreadProc(Thread: TThread): Integer;
var
FreeThread: Boolean;
begin
try
if not Thread.Terminated then
try
Thread.Execute;
except
Thread.FFatalException := AcquireExceptionObject;
end;
finally
FreeThread := Thread.FFreeOnTerminate;
Result := Thread.FReturnValue;

// thread hangs here !!!
Thread.DoTerminate;

// never gets HERE !!!! when a OnTerminate is assigned to the
thread
Thread.FFinished := True;
SignalSyncEvent;
if FreeThread then Thread.Free;
EndThread(Result);
end;
end;
________________________
procedure TThreadConnection.Execute;
begin
FreeOnTerminate := True;
OnTerminate := DoTerminate;

while not Terminated do
begin
try
DoWork;
except
end;
if not Terminated then
Suspend;
end;
end;
________________________
procedure TThreadConnection.DoTerminate(Sender: TObject);
begin
SendDebug(LogMessage+' - TERMINATED !!!! ');
//send the event on the client
(IInterface(FComServer) as IComServerNotify).FireTerminate;
end;
________________________
on the server class:

procedure TComServer.Terminate;
var
retVal: Cardinal;
begin
SendDebug('SERVER: Terminate demand');
FThreadConnection.Terminate;
FThreadConnection.Resume;
end;
________________________


Thanks for help,
Cristian

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.