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 7045415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:31:40+00:00 2026-05-28T02:31:40+00:00

What I basically want is to start AsyncCall and proceed with my code loading.

  • 0

What I basically want is to start AsyncCall and proceed with my code loading. I have Interface section that consumes lots of time (600+ms) and I want to load this code in independent thread.

I’ve tried to use AsyncCall to make something like this:

procedure Load;
begin
...
end;

initialization
  AsyncCall(@Load, []); // or LocalAsyncCall(@Load)

However, this Load procedure actually starts in Main thread and not in the new created thread. How can I force the Load procedure to be loaded in any thread other than MainThread?

I can create TThread and Execute this but I want to force AsyncCall or LocalAsyncCall or anything from AsyncCall library to make to work.

Thanks for your help.

  • 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-28T02:31:41+00:00Added an answer on May 28, 2026 at 2:31 am

    The problem is that your code is not retaining the IAsyncCall interface that is returned by the AsyncCall function.

    AsyncCall(@Load, []);
    //AsyncCall returns an IAsyncCall interface,
    //but this code does not take a reference to it
    

    Because of this, the interface that is returned has its reference count decremented to zero as soon as the initialization section completes. This therefore frees the object that implements the interface which does this:

    destructor TAsyncCall.Destroy;
    begin
      if FCall <> nil then
      begin
        try
    -->   FCall.Sync; // throw raised exceptions here
        finally
          FCall.Free;
        end;
      end;
      inherited Destroy;
    end;
    

    The key line is the call to Sync which forces the asynchronous call to be executed to completion. All this happens in the main thread which explains the behaviour that you report.


    The solution is that you simply need to keep the IAsyncCall interface alive by storing it in a variable.

    var
      a: IAsyncCall;
    
    initialization
      a := AsyncCall(@Load, []);
    

    In the real code you need to ensure that Load had completed before running any code that is reliant on Load. When your program reached a point where it required Load to have been called it has to call Sync on the IAsyncCall interface.

    So you might write it something like this.

    unit MyUnit;
    
    interface
    
    procedure EnsureLoaded;
    
    implementation
    
    uses
      AsyncCalls;
    
    ....
    
    procedure Load;
    begin
      ....
    end;
    
    var
      LoadAsyncCall: IAsyncCall;
    
    procedure EnsureLoaded;
    begin
      LoadAsyncCall := nil;//this will effect a call to Sync
    end;
    
    initialization
      LoadAsyncCall := AsyncCall(@Load, []);
    
    end.
    

    The call EnsureLoaded from other units that required Load to have run. Or, alternatively, call EnsureLoaded from any methods exported by MyUnit that depended on Load having run. The latter option has much better encapsulation.

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

Sidebar

Related Questions

Basically, I have a block of memory allocated using malloc that I want to
Basically I want to have a button to start a new activity after login.
I'm trying to start the del command using System.Diagnostic.Process. Basically I want to delete
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
So I basically want to have a static method in my AR class to
I have a 2-dimensional array of objects and I basically want to databind each
I want to write some VBA script so that when I start my access
Basically I want an arbitrarily large stack. I know that's not possible, but could
I have a string: $uri = start/test/go/; Basically I need to know which regular
I basically want to implement a Label and have it constantly showing information to

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.