Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Streamwriter need shareread while write is happening

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

    Streamwriter need shareread while write is happening

    private StreamWriter sw;
    sw = File.AppendText(sPath); // Open the path for writing
    sw.WriteLine(sLine); // Append a new line to the file
    sw.Close();
    I am writing text to a file and sometimes a second indicator will be reading that text while the first process has it locked, causing the second indi to abort, even tho it is in a try, catch block
    So I either need parms to share the file, or a way to catch the abort of the second indi and retry the read. Thanks, Ken

    #2
    Hello kenz987,

    In general what you are doing will not work as expected because two items cannot share access to a file at the same time. The two scripts are not going to work in unison to read/write/close.

    What specifically are you trying to do with the shared file or what is its purpose in your scripts?

    You likely need to use a C# structure for what you are trying to do if you mean to share some data, writing/reading a file is only realistic if the rate at which the read/write occur is spaced out so they are not conflicting.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      OK, skip that, But why did the second indi abort, the error was in a try/catch block??? Is there any way to keep an indi alive no matter the errors?

      Comment


        #4
        Hello kenz987,

        I couldn't say without a specific example. There is not a way to keep the indicator alive in case of errors, the platform expects to stop it in case of an error. Generally we just suggest to avoid using try/catch so that you can catch the very first exception and not allow the script to move past that point. This helps in debugging.


        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by MarianApalaghiei, Today, 10:49 PM
        2 responses
        8 views
        0 likes
        Last Post MarianApalaghiei  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        8 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        37 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        46 views
        0 likes
        Last Post bill2023  
        Working...
        X