Jump to content
Max Terentiev

Is it's safe to destroy TSslHttpCli while http request in progress ?

Recommended Posts

Hi,

 

I create and use TsslHttpCli like this:

 

Http=new TSslHttpCli(NULL);
SslContext=new TSslContext(NULL);
Http->SslContext=SslContext;

Http->OnRequestDone=HttpRequestDone;
Http->URL="https://api.server.ru/api/data-list/";
Http->GetASync();

If I call GetASync() can I destroy TsslHttpCli at any time before they fire OnRequestDone event ? For example, if user close program can I run code like this:

 

delete Http; // or Http.Free; on pascal

Or I must call TsslHttpCli.Abort or AbortComponent and wait until they ready for destruction (in this case - how to understand is it's ready for destruction)?

 

Thanks for help !

 

Share this post


Link to post

You should not destroy the component from an event handler of that component (general rule, not specific of ICS) or you'll experience access violation or other strange behavior.

From an event handler, you can defer the destroy using a PostMessage of a custom message. That is what TForm.Release does by the way.

 

Share this post


Link to post

So, I can destroy TsslHttpCli from any another application event (like CancelButton.OnClick, Form.OnClose, etc) without any special care ? No matter is TsslHttpCli idle or process some request ?

Share this post


Link to post

Yes. The remote site will experience and abort error if a transfer is occurring.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×