Very simple example (actually within the code):
The problem is I'm trying to do this the so-called "safe" way (using TerminateThread actually makes this program work *right*), and yet the thread continues after the form is forced closed (works otherwise), generating access violations in "UpdateStuff".
OnCloseQuery produces the same result. So...thoughts?
Code:
procedure UpdateThread.Execute;
begin
While not Terminated do
begin
Synchronize(Form1.UpdateStuff);
WaitForSingleObject(Self.Handle, 50); // this is for a "safe" thread delay, attempting to not soak the CPU.
end;
end;
procedure TForm1.UpdateStuff;
begin
// do stuff with Form1 that generates Access Violations.
end;
The problem is I'm trying to do this the so-called "safe" way (using TerminateThread actually makes this program work *right*), and yet the thread continues after the form is forced closed (works otherwise), generating access violations in "UpdateStuff".
Code:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ut.Terminate;
ut.WaitFor;
ut.Free;
end;
OnCloseQuery produces the same result. So...thoughts?