Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MultiThreading Calcs

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

    MultiThreading Calcs

    I've created a class within my NT indicator that processes some data (High, Low, Close, etc...) that's generated from the OnBarUpdate eventHandler and it passes this data to my class to be processed which I've created a managed thread to handle the processing...

    Ninja keeps crashing whenever I attempt to add the indicator to a chart. Is there anything in particular I need to know about as far as using managed threads with NT?


    Example:

    MyCls myCls = new MyCls();

    void OnBarUpdate()
    {
    double high = High[0];
    double low = Low[0];
    double close = Close[0];

    string data = string.Format("{0},{1},{2}",high,low,close);
    myCls.GetData(data);
    }

    // my class
    class MyCls
    {
    EventWaitHandle ewh = new AutoResetEvent(false);
    object sync = new object();
    Queue<string> que = new Queue<string>();
    Thread t = new Thread(worker);

    public MyCls()
    {
    t.IsBackground = true;
    t.Start();
    }

    public void GetData(string data)
    {
    lock(sync)
    {
    que.Enqueue(data);
    }
    ewh.Set();
    }

    private void worker()
    {
    while(true)
    {
    lock(sync)
    {
    // get data from que.Dequeue();
    // blah, blah, blah...
    }

    // process data....blah, blah, blah...
    // after processing data block thread
    ewh.WaitOne();
    }
    }
    Last edited by d.allen101; 12-10-2011, 09:38 AM.

    #2
    d.allen101, I will have someone get back to you on Monday with an answer to your question.
    AustinNinjaTrader Customer Service

    Comment


      #3
      d.allen101, are there any error shown in the log tab when you add your script?

      Comment


        #4
        i know very little about using/debugging NT, someone told to how to get to stack trace and i went to it and found the exception. it was because i was sharing my commandObject and connectionObject across multiple threads. i should have had an exclusive lock on those objects or made them local in scope to each thread. i corrected it so everything in fine now, but thanks for getting back to me.

        Comment


          #5
          Glad to hear you could resolve it!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          600 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
          558 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