title: Delphi Queue and Synchronize
body: <p>I am reading Nick Hodges online and I have discovered the Queue but it is not behaving as I've expected and I couldn't understand what him and the documentation say. Look at this code:</p>
  
  <pre><code> TThread.CreateAnonymousThread(
    procedure
     begin
  
       TThread.Queue(TThread.Current, procedure
                                            begin
                                             Memo1.Lines.Clear;
                                             Memo1.Lines.Add('start');
                                            end);
  
       Sleep(2000);
  
       TThread.Synchronize(TThread.Current, procedure
                                            begin
                                             Memo1.Lines.Add('end');
                                            end);
  
     end
   ).Start;
  </code></pre>
  
  <p>I always use <code>Synchronize</code> but this time I have tried with <code>Queue</code> because according to Nick it is better in case of multiple requests since they won't be "serialized" and executed one by one. The code above works fine. Why this is not working instead?</p>
  
  <pre><code> TThread.CreateAnonymousThread(
    procedure
     begin
  
       TThread.Queue(TThread.Current, procedure
                                            begin
                                             Memo1.Lines.Clear;
                                             Memo1.Lines.Add('start');
                                            end);
  
       Sleep(2000);
  
       TThread.Queue(TThread.Current, procedure
                                            begin
                                             Memo1.Lines.Add('end');
                                            end);
  
     end
   ).Start;
  </code></pre>
  
  <p>In this case the Memo outputs the <code>start</code> but not the end. When I call:</p>
  
  <ul>
  <li>Synchronize on the first and Synchronize on the second it works</li>
  <li>Queue on the first and Synchronize on the second it works</li>
  <li>Queue both times it's not working because I see only the <code>start</code> in the memo</li>
  </ul>