Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
AddOn vs NinjaTrader Exit/Shutdown
Collapse
X
-
AddOn vs NinjaTrader Exit/Shutdown
When Exiting (shutting down) NinjaTrader, how should one handle disposing of AddOn variables declared in AddOnBase that should, in normal usage, be Disposed, or at least set to null? For example, HttpClient or similar. Is there any need (or good reason) to do this when Exiting? If so, where is that done?
Thanks.Tags: None
-
Hello jeronymite,
Thank you for your reply.
Yes, is important to unsubscribe from event handlers and dispose of unused resources when they are no longer needed. The OnWindowDestroyed() method can be used to clean up any resources when closing out of NinjaTrader.
I'm attaching this example AddOnShell that demonstrates cleaning up a click handler and removing the menu item for the window from the Control Center when the Control Center is closed.
Please let us know if we may be of further assistance to you.
Attached Files
-
Thanks, Kate.
This is good to know. Nonetheless, OnWindowDestroyed is called when a NinjaScript object is compiled as, apparently, that causes all existing windows to be destroyed and recreated. Is there a way to determine unequivocally that NinjaTrader is shutting down and that's why the windows are destroyed?
Thanks.
Comment
-
Thanks again, Kate.
Actually, all windows are destroyed and recreated when an AddOn is compiled. This can easily be seen if one prints a diagnostic message in both OnWindowDestroyed and OnWindowCreated identifying the window being destroyed or created. The ControlCenter is always one of those windows. So, without further explicit and definitive information, it is not possible, from within OnWindowDestroyed alone, to know if NinjaTrader is shutting down or if it is a recompile.
Grateful for your further investigation to determine how one might unequivocally know that NinjaTrader is shutting down as opposed to a recompile being done.
Thanks.
Comment
-
Hello jeronymite,
Thank you for your reply.
There would not be an alternate method to determine whether NinjaTrader is shutting down. We do have an existing feature request to add a property to OnWindowDestroyed() that tells if the addon window is being closed by the user or by NinjaTrader closing the workspace / shutting down. I have added a vote on your behalf to this request, which is being tracked using the number SFT-4752.
As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.
Release Notes — https://ninjatrader.com/support/help...ease_notes.htm
Please let us know if we may be of further assistance to you.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment