Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Thread ID

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

    Thread ID

    Hi,

    According to this link:


    There are three threads that are running. If I want to ID and only execute certain code on thread #3, the indicator code thread, how can I find that threads ID and isolate it?

    V/R,
    --Maxim

    #2
    Hello DieSlower,

    Thank you for your note.

    This would be outside of what we would be able to support. However, you may find some guidance in this post, this unsupported example of finding chart indicators may help. Specifically using Indicator.ChartControl.dispatcher.invokeasync():



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Right, I have used the dispatcher functions for threading before, which is how I can get the thread IDs, but is there some place where we know that the threads are started...in certain order? That way I can get the IDs say of the first 2 threads that start, and know for sure that it is the thread that is started right after them the one I need?

      Is there some function in NT where this startup is visible, or detectable?

      --Maxim

      Comment


        #4
        Hello DieSlower,

        Thank you for your note.

        There would not be a supported way to achieve that. However, we may be able to give some direction at least if you can elaborate a bit on what you're trying to achieve.

        Thanks in advance; I look forward to assisting you further.

        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Sure!

          There are many uses for this, but a good example is for debugging and various messages.
          If I want to know when my settings are loaded and when my strategy exits or terminates, I put print statements into OnStateChange() for instance under State == State.DataLoaded and State == State.Turminated. But because it is being hit by all three threads, it is being printed three times in the console.

          I only want to see the messages once, when the main logic thread is doing the execution. This can be used in more advanced cases when other code, not just Print() is used.
          So I need a way to figure out when I'm actually running in the main thread...some way to get its ID. Then I can compare it to the ID of the current thread, and only run my code when the right ID is hit.

          Comment


            #6
            Hello DieSlower,

            Thank you for your reply.

            We couldn't assist further with custom multi threading approaches, but you could use C# code to identify the thread that is running:

            Print(System.Threading.Thread.CurrentThread.Manage dThreadId);

            Some of the multiple prints you are seeing may be explained by the NinjaScript Lifecycle:



            However, On State Change would generally called by UI Thread when adding, modifying, deleting NinjaScript settings from the UI but is considered to be able to be called by any thread. Example:
            1. Called by ThreadPool for State.Historical
            2. Called by Instrument thread for State.Realtime.
            3. Called by UI/ThreadPool/Instrument Thread in the case of exception and going to finalized state for State.Terminated/State.Finalized.
            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Waxavi, Today, 02:10 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            8 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Working...
            X