Hello dz,
Change this. Its from top of my head so can be syntax errors. You have
to move the destroy of the server also in the Execute mehod:
Destructor TServerThrd.Destroy;
Begin
Try
// this must in the Execute method
// If Assigned(FSocketSrv) Then Begin
// FSocketSrv.Free; // <<-- HERE! (waits forever)
// End;
Finally
Inherited Destroy;
End;
End;
Procedure TServerThrd.Execute;
Begin
Try
FSocketSrv := TWSocketThrdServer.Create(Nil);
FSocketSrv.Listen();
FSocketSrv.MessageLoop;
Finally
// Add
FSocketSrv.Free;
End;
End;
---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz
Thursday, October 4, 2007, 18:57, [EMAIL PROTECTED] wrote:
> Hello:
> I'm having a problem with the TWSocketThrdServer.
> My application has a worker thread that contains a
> TWSocketThrdServer member to handle all incoming
> requests. When the main thread finishes, it sends a
> WM_QUIT message to the worker thread, which then
> finishes and frees the TWSocketThrdServer. However,
> if there are clients connected, the thrdserver stalls
> in its destructor, while waiting for all its threads
> to finish.
> It only loops forever when there are clients
> connected and the worker thread is terminated. But
> if there are no clients connected, it works fine.
> Can someone offer any help? Most likely I'm doing
> something wrong. (Below is an example of my code.)
> Also, I need to be able to terminate the entire
> application if something goes wrong while processing
> clients. What is the best way to do this? Should I
> post a message to the main thread from a
> TWSocketThrdServer event in the worker thread?
> Thanks!
> dZ.
> My code is somewhat like this (this is very much
> simplified):
> Interface
> Type
> TServerThrd = Class(TThread)
> Private
> FSocketSrv: TWSocketThrdServer;
> Public
> Constructor Create; Reintroduce;
> Destructor Destroy; Override;
> Procedure Execute; Override;
> End;
> TQApp = Class(TObject)
> Private
> FServerThrd : TServerThrd;
> Public
> Constructor Create;
> Destructor Destroy; Override;
> End;
> Implementation
> { TQApp }
> Constructor TQApp.Create;
> Begin
> FServerThrd := TServerThrd.Create(False);
> End;
> Destructor TQApp.Destroy
> Begin
> Try
> Try
> PostThreadMessage(FServerThrd.ThreadID,WM_QUIT,0,0);
> Finally
> FServerThrd.WaitFor;
> FServerThrd.Free;
> End;
> Finally
> Inherited Destroy;
> End;
> End;
> { TServerThrd }
> Constructor TServerThrd.Create;
> Begin
> Inherited Create(True);
> End;
> Destructor TServerThrd.Destroy;
> Begin
> Try
> If Assigned(FSocketSrv) Then Begin
> FSocketSrv.Free; // <<-- HERE! (waits forever)
> End;
> Finally
> Inherited Destroy;
> End;
> End;
> Procedure TServerThrd.Execute;
> Begin
> Try
> FSocketSrv := TWSocketThrdServer.Create(Nil);
> FSocketSrv.Listen();
> FSocketSrv.MessageLoop;
> Finally
> // do other cleanup
> End;
> End;
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be