Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:57:08+00:00 2026-06-16T00:57:08+00:00

How can I implement a message loop within a thread using OTL? Application.ProcessMessages; is

  • 0

How can I implement a message loop within a thread using OTL? Application.ProcessMessages; is what i used so far but it isn’t very safe to use it.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:57:09+00:00Added an answer on June 16, 2026 at 12:57 am

    This is how I pull messages off a thread’s queue:

    while GetMessage(Msg, 0, 0, 0) and not Terminated do begin
      Try
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      Except
        Application.HandleException(Self);
      End;
    end;
    

    Using Application.ProcessMessages will pull messages of the queue of the calling thread. But it’s not appropriate to use in a message loop because it won’t block. That’s why you use GetMessage. It blocks if the queue is empty. And Application.ProcessMessages also calls other TApplication methods that are not designed to be thread safe. So there are plenty of reasons not to call it from a thread other than the main thread.

    When you need to terminate the thread, then I do this:

    Terminate;
    PostThreadMessage(ThreadID, WM_NULL, 0, 0);
    //wake the thread so that it can notice that it has terminated
    

    None of this is OTL specific. This code all is intended to live in a TThread descendent. However, the ideas are transferable.


    In the comments you indicate that you want to run a busy, non-blocking message loop. You would use PeekMessage for that.

    while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do begin
      Try
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      Except
        Application.HandleException(Self);
      End;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can implement both variants - it's easy. But I'm interested: what approach is
How can implement reordring in winforms datagridview by using the feature of drag and
I wrote a thread application which runs an infinite loop. The problem is since
How can i implement message security in WCF with custom attributes, One way of
I'm trying to implement a critical section in CUDA using atomic instructions, but I
We want to implement a News feed where a user can see messages broadcasted
Can someone please tell me how I can implement the following line of pseudo-code.
Anyone knows how i can implement re-arrangable divs (Drag the divs around on the
How I can implement dynamic Jtree, which shows created instances of clases? For example,
I know that classes can implement various special methods, such as __iter__ , __setitem__

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.