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.

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        41 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        27 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        45 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        37 views
        0 likes
        Last Post CarlTrading  
        Working...
        X