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 GussJ, 03-04-2020, 03:11 PM
        15 responses
        3,268 views
        0 likes
        Last Post xiinteractive  
        Started by Tim-c, Today, 02:10 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        2 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        50 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        10 responses
        401 views
        1 like
        Last Post beobast
        by beobast
         
        Working...
        X