Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. bug(or my problem) in File.Open using FileShare.Write

bug(or my problem) in File.Open using FileShare.Write

Scheduled Pinned Locked Moved Visual Basic
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    carlos_rocha
    wrote on last edited by
    #1

    Hi! I have an app that writes to a log file all the app's steps. I have several threads writing several times per second to the log file. The thing is that i have detected an exception with one of those writings, when i try to OPEN the log file. I use FileShare.Write so that there's no problem with writes form several threads at the same time(i thought).Did anybody experienced such a problem or is it my bug? I only write to the log in one function and i close the filestrems an the end.The code is: Try fs = File.Open(logPath & Format(Now(), "yyyyMMdd") & ".txt", FileMode.Append, FileAccess.Write, FileShare.Write) fsWriter = New StreamWriter(fs) fsWriter.WriteLine(Now & vbTab & entryString) Catch ex As Exception writeToErrorLog(ex.ToString) Finally If Not fsWriter Is Nothing Then fsWriter.Close() End If If Not fs Is Nothing Then fs.Close() End If End Try Never say never

    D 1 Reply Last reply
    0
    • C carlos_rocha

      Hi! I have an app that writes to a log file all the app's steps. I have several threads writing several times per second to the log file. The thing is that i have detected an exception with one of those writings, when i try to OPEN the log file. I use FileShare.Write so that there's no problem with writes form several threads at the same time(i thought).Did anybody experienced such a problem or is it my bug? I only write to the log in one function and i close the filestrems an the end.The code is: Try fs = File.Open(logPath & Format(Now(), "yyyyMMdd") & ".txt", FileMode.Append, FileAccess.Write, FileShare.Write) fsWriter = New StreamWriter(fs) fsWriter.WriteLine(Now & vbTab & entryString) Catch ex As Exception writeToErrorLog(ex.ToString) Finally If Not fsWriter Is Nothing Then fsWriter.Close() End If If Not fs Is Nothing Then fs.Close() End If End Try Never say never

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You just told us "It's broke". What's the exception message? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You just told us "It's broke". What's the exception message? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        C Offline
        C Offline
        carlos_rocha
        wrote on last edited by
        #3

        Ops...Sorry :P System.IO.IOException: The process cannot access the file "c:\myFile.txt" because it is being used by another process. Never say never

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups