Unit ThreadSyncTest; { This unit is aimed at tracking down a very specific bug. Sometimes Thread.Synchronize does not do what it is supposed to to. It calls the method in the current thread, not the main GUI thread. It turns out that Delphi's Thread.Syncrhonize works exactly as it should. The bug was in my code. I wasn't calling Thread.Synchronize when I thought I was. D'oh! } Interface Procedure DoThreadSyncTest; Implementation Uses Windows, Classes, SysUtils; Type TTestThread = Class(TThread) Protected Procedure Execute; Override; Procedure InGuiThread; End; Procedure TTestThread.Execute; Var OtherThread : TTestThread; Begin Try Assert(GetCurrentThreadId <> MainThreadId, 'Problem before Sync.'); OtherThread := TTestThread.Create(True); OtherThread. Synchronize(InGuiThread); Assert(GetCurrentThreadId <> MainThreadId, 'Problem after Sync.'); Except On Ex : Exception Do Begin { Past experience shows that Delphi is very bad about reporting exceptions in any thread but the GUI thread. } MessageBox(0, PChar(Ex.Message), PChar(Ex.ClassName+''), 0); Halt End End End; Procedure TTestThread.InGuiThread; Begin Assert(GetCurrentThreadId = MainThreadId, 'Problem in Sync.') End; Procedure DoThreadSyncTest; Var TestThread : TTestThread; Begin TestThread := TTestThread.Create(True); TestThread.FreeOnTerminate := True; TestThread.Resume End; End.