08-07-2018, 07:36 PM
(08-07-2018, 06:45 PM)rlebeau Wrote: The safer approach is to NEVER use the TWinControl.Handle properly across thread boundaries. Allocate your own HWND, such as with the RTL's AllocateHWnd() function, and then you can safely post messages to that HWND all you want.
I made that change this morning by creating my own HWND as such:
var
hSyncWnd: HWND;
procedure TMainForm.FormCreate(Sender: TObject);
begin
TThread.CurrentThread.NameThreadForDebugging('VCLThread');
hSyncWnd := AllocateHWnd(SyncMessage);
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
DeallocateHWnd(hSyncWnd);
end;
And then calling it from my worker thread with:
PostMessage(hSyncWnd, WM_User + 2, Mask, 0);
While that works, I've since got another crash on Active := False so that wasn't the problem.
(08-07-2018, 06:45 PM)rlebeau Wrote: I've heard of the TMethodImplementationIntercept class, but am not aware of whether it creates a worker thread or not.
That turns out to be the main VCL thread. I started naming all my own threads including that one and the ID number matches what Process Explorer shows. Which makes sense because I'm calling Active := False in a button click event. But moving that to a worker thread (which I tried already) will just mean the worker thread will be the unkillable thread.
Any thoughts on the MAXSTACKSIZE? Yesterday I changed it to 512K and could not produce a crash. I changed back to 256K and got one crash today. May just be a coincidence.

