Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using the "using()" statement with StreamReader/Writer

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

    using the "using()" statement with StreamReader/Writer

    Is it "wise" to use the "using()" statement while reading, and writing to the file system in NT? I actually read the file in without using() because it's a one time shot in the OnStartUp() method and I "sr.Close()" the file when it's done, but when writing I have a:
    using(StreamWriter sw = new StreamWriter([file]))
    {
    sw.WriteLine("blah");
    }

    Each time a tick comes in. Is that too much overhead? Is there a more effiicient way? I'm experimenting because I've been getting "cannot access [file], it is being used by another process" (something similar) when trying to switch back and forth between diff. instruments/time frames in same chart window. This happens on and off, and I haven't figured out *exactly* which moves create that error. I'm assuming the write is staying open while the read is trying to access, hence the using() approach.

    #2
    Unfortunately this level of C# is beyond what we can offer support for. Hopefully a community member would have some ideas for you.

    All I can reference you to is how the StreamReader and StreamWriter are used in our reference samples here:

    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      Could you have StreamWriter added to the F1 help? Maybe just me, but I cant locate anything there on it.

      Jon

      Comment


        #4
        Correct Jon, this is not in the helpguide, but in the list of educational resources we offer on NinjaScript on the forums here as well - http://www.ninjatrader.com/support/f...splay.php?f=29

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        574 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        332 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X