Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Is it ok to use Thread.Sleep(0) in OnBarUpdate() of an Indicator ?
I ask because the indicator I was using had a lot of plots and this seems to be the reason it would grind NT8 to a halt so that it took several seconds between clicking on a tab to change to that chart... or for a dialog like Data series to pop up.
I added it, so far so good- very responsive NT8 UI and no problems I can see.. but I'm just wondering if anyone can forsee any problems here.. I'm not a C# or NinjaScript expert.
Can you help answer these questions from other members on NexusFi?
A sleep for 0 millisecond will do nothing. Using a value > 0 will only delay the moment when the buggy/heavy computing stuff will be done, so not useful either. Also it will only delay one thread, not the GUI thread.
Globally a bad idea.
well it seems to have eliminated my responsiveness problems. And cpu usage also drops for ninjatrader (I have several charts open)
Sleep(0) does something, I have used it in other languages in many situations to reduce cpu usage and delays when you're in a loop... it is similar to Yield() but with differences... https://stackoverflow.com/a/16584612/270143
as you can imagine, you don't want to have to wait several seconds or longer (could be 5 or 10 seconds or more sometimes) every time you switch to another chart tab or open a dialog.
I think this problem is not common because most indicators only use a handful of plots.