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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      75 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      146 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      50 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      54 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X