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