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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        79 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        45 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        66 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X