Необходимо выполнить WebRequest при ondeinit (специфично для закрытия диаграммы), но это невозможно внутри ondenit

 

I have an advisor and I have to control the number of contracts (lots) that the user can trade, so I have an API, and when the advisor is initialized, the web request places the amount in the database, and if the advisor or set is deleted, that one is requested the same web service and removes these contracts, but I have a problem when closing the diagram manually, it seems that the closing of the diagram is happening asynchronously and I cannot execute the web request placed in the ondenit function, I get an http error, but only when closing the diagram manually on the X button, have any ideas how to fix this?