Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Async Thready is not spanning immedeatly

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

    Async Thready is not spanning immedeatly

    Hi,

    In Account.PositionUpdate , I am initiating separate thread with below code to monitor the SL and PT orders. The Async thread it not starting immediately, it is taking almost 30seconds to span. How to span async thread immediately ?

    ChartControl.Dispatcher.InvokeAsync(new Action(() => {
    // monitoring code
    } ));

    #2
    Hello nandhumca,

    Thank you for your post.

    The InvokeAysc() call invokes the code in the body at the next thread availability. If there is some other part of your code that is looping or doing something repetitive where it is also dispatching the ChartControl, it could prevent your code in OnPositionUpdate from running quickly.

    Could you provide a reduced sample of your script to show what you're doing in the InvokeAsync() part of the code, so we can get a better idea of what may be happening?

    Thank you in advance.

    Comment


      #3
      my very first statement itself to print the timestamp. That line itself was executed afer 30+ seconds. If I pass the priority into InvokeAsync, that will trigger the async thread immediately ? if so which priority , i need to use ?

      Code:
      private void InternalPositionUpdate(object sender, PositionEventArgs e)
      {​
      PrintLogAll(string.Format(DateTime.Now.ToString("y yyy-MM-dd HH:mm:ss.fff") + " OnPosUpdate : " +" " + sender+ " "+ "Instrument: {0} MarketPosition: {1} AveragePrice: {2} Quantity: {3}",
      e.Position.Instrument.FullName, e.MarketPosition, e.AveragePrice, e.Position.Quantity));​
      
      ChartControl.Dispatcher.InvokeAsync(new Action(() => {
      PrintLogAll(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " OnPosUpdate : ASYNC " +" " + sender+ " Async Start Time Pos");​
      }));
      
      }​

      Comment


        #4
        Hello nandhumca,

        Thank you for your response.

        From this snippet it isn't clear to me what could be causing the delay. If possible, could you please provide a reduced version of the script that demonstrates the issue for testing on our end?

        When you are using this script, where you are submitting your orders from?

        Do you have anything else applied to the chart when testing this out, or is just this script applied to the chart?

        I look forward to assisting further.

        Comment


          #5
          I will share you one simple working indicator to reproduce the issue.
          Last edited by nandhumca; 04-09-2024, 09:39 AM.

          Comment


            #6
            Hello nandhumca,

            Do you have a script we can test out? If you are uncomfortable sharing the script here, you can send it to us at scriptingsupport[AT]ninjatrader.com. In the body of the email include: 04354099 Attn Gaby.

            Do you have anything else applied to the chart when testing this out, or is just this script applied to the chart?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X