Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Heavy CPU and memory usage using Dispatcher.InvokeAsync

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Heavy CPU and memory usage using Dispatcher.InvokeAsync

    I finally find a nice solution to my button issues but it is eating up computer resources. I did all the development on my desktop which has a good process or and 32gb ram and did notice a little lag in the strategy opening in the chart but then tried to use it on my VPS computer and it basically just hangs up or crashes it. Wondering if I am doing something wrong or there is another method that doesn't kill a computer. as soon as I comment out this code the computer and strategy are normal again.

    Dispatcher.InvokeAsync((() =>
    {
    if(golongButton != null && goshortButton != null && exitButton !=null)
    {
    if(Position.MarketPosition == MarketPosition.Long)
    {
    golongButton.Content = "Go Long";
    golongButton.Name = "GoLongButton";
    golongButtonClicked = false;
    longEnable = false;
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    goshortButton.Content = "Go Short";
    goshortButton.Name = "GoShortButton";
    goshortButtonClicked = false;
    shortEnable = false;
    }
    else if (Position.MarketPosition == MarketPosition.Flat)
    {
    exitButton.Content = "Close All";
    exitButtonClicked = false;
    exitEnable = false;
    }

    }}));

    #2
    Hello set2win,

    Thanks for your post.

    Is this code being used frequently?

    Are you able to move that code to be in the button event instead of in OnBarUpdate()? If so, do you see improved performance when the code is moved?

    I look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I added If (State == State.RealTime) prior to this Dispatcher as it is only needed to set the button state in realtime. This fixed the problem.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X