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

  • SEARCH
  • Home
  • 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 1019133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:57:51+00:00 2026-05-16T10:57:51+00:00

I have to execute some code in the context of the main thread. I

  • 0

I have to execute some code in the context of the main thread. I am using Lazarus + FPC. I receive an event from a thread inside a DLL (shared library if on linux) and my callback function gets called. Note that this function is not a member of any class but a standalone traditional function with a “cdecl” directive attached.

I have to triger a coresponding property event handler for each such message I receive. And these events have to be passed on in the context of the main thread. I know of two such solutions:

  1. PostMessage
  2. Application.QueueAsyncCall

The first one is ok, but it requires a window handle. And since this is a library code no handle is available. AllocateHWND is not an option since it is not cross platform. I know I can create a dummy form but this is a very bad solution

The second works ok, but I have a problem, that the call is not processed until I move a mouse inside application for instance. Maybe I am doing something wrong I don’t know. I is just like my call is being processed only when message processing kicks in. But this can be a long wait apparently.

So I want to know what is the best solution here (probably QueueAsyncCall) and how I can be sure that my message (call) will be processed in acceptable timeframe?

  • 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-05-16T10:57:52+00:00Added an answer on May 16, 2026 at 10:57 am

    You can not be 100% sure, just like you can’t in any non-realtime system. If the mainthread hangs, it won’t check for messages or other events in the main loop. This is normal.

    The only thing you can do is to avoid doing stuff in the mainthread that can take a long time. It’s the trick of the trade to exactly judge what is necessary and what is not. Some realtime oriented people move all filesystem access to threads, and keep the GUI strictly for UI, just because if an user configures a path on a network share for this or the other, a problem with the share can easily cause a long timeout wait, of minutes even.

    If I look at application.queueasynccall, I see no threadsafe processing (no locking or locked queues), so that one is out.

    I know postmessage is emulated by Lazarus to some degree on non Windows, and I checked the implementation and it does have lock, so I assume it is multithreading safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.