Is it safe to override Free method? I'm asking because I would like to use something like this. I know it's very ugly to use TerminateThread, but in my case it's very critical to kill the process with all its threads immediately.
I've seen the __free method declared in System.pas, but I don't know if it has something to do with the TObject.Free method and that's the reason why I'm asking if it's safe.
type
TMyThread = class(TThread)
private
destructor Destroy; override;
public
procedure Execute; override;
constructor Create;
procedure Free(const Force: Boolean = False); // is it safe to use this?
end;
procedure TMyThread.Free(const Force: Boolean = False);
begin
if not Force then
begin
Terminate;
WaitFor;
end
else
TerminateThread(Handle, 0);
inherited Free;
end;
destructor TMyThread.Destroy;
begin
// free resources etc.
inherited Destroy;
end;
Thank you