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 Hwop38, 05-04-2026, 07:02 PM
          0 responses
          160 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          307 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          245 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          349 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          178 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X