Error writing to a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fniles

    #1

    Error writing to a file

    For each message that my application receives I write it to a log file.
    Since each message is its own thread, many time I get the error "The process
    cannot access the file "c:\bestdesk\lo g\RiskIn051707. txt" because it is
    being used by another process." Is there a way to get around this error ? I
    can do the same thing in VB6 with no problem. Thank you.

    This is how I write to the file:
    Sub ProcessEachMess age
    Dim swLog As StreamWriter

    swLog = New StreamWriter(sP ath & "\bestdesk\log\ RiskIn" &
    Date.Now.ToStri ng("MMddyy") & ".txt", True)
    swLog.Write(Now & "NEWTRADE sMessage = " & Message & vbCrLf)
    swLog.Close()
    swLog = Nothing
    :


  • Cor Ligthert [MVP]

    #2
    Re: Error writing to a file

    fliles,

    I am not sure but in Net there is the magic word flush too.

    http://msdn2.microsoft.com/en-us/lib...sh(VS.71).aspx

    Be always aware that the "Nothing" keyword is to set reference. It has
    nothing to do with the real object.

    Cor



    "fniles" <fniles@pfmail. comschreef in bericht
    news:u%23WqgcJm HHA.3888@TK2MSF TNGP05.phx.gbl. ..
    For each message that my application receives I write it to a log file.
    Since each message is its own thread, many time I get the error "The
    process cannot access the file "c:\bestdesk\lo g\RiskIn051707. txt" because
    it is being used by another process." Is there a way to get around this
    error ? I can do the same thing in VB6 with no problem. Thank you.
    >
    This is how I write to the file:
    Sub ProcessEachMess age
    Dim swLog As StreamWriter
    >
    swLog = New StreamWriter(sP ath & "\bestdesk\log\ RiskIn" &
    Date.Now.ToStri ng("MMddyy") & ".txt", True)
    swLog.Write(Now & "NEWTRADE sMessage = " & Message & vbCrLf)
    swLog.Close()
    swLog = Nothing
    :
    >

    Comment

    • fniles

      #3
      Re: Error writing to a file

      Thanks.
      What did you mean by ""Nothing" keyword is to set reference." ?

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
      news:ujtByqJmHH A.4132@TK2MSFTN GP02.phx.gbl...
      fliles,
      >
      I am not sure but in Net there is the magic word flush too.
      >
      http://msdn2.microsoft.com/en-us/lib...sh(VS.71).aspx
      >
      Be always aware that the "Nothing" keyword is to set reference. It has
      nothing to do with the real object.
      >
      Cor
      >
      >
      >
      "fniles" <fniles@pfmail. comschreef in bericht
      news:u%23WqgcJm HHA.3888@TK2MSF TNGP05.phx.gbl. ..
      >For each message that my application receives I write it to a log file.
      >Since each message is its own thread, many time I get the error "The
      >process cannot access the file "c:\bestdesk\lo g\RiskIn051707. txt" because
      >it is being used by another process." Is there a way to get around this
      >error ? I can do the same thing in VB6 with no problem. Thank you.
      >>
      >This is how I write to the file:
      >Sub ProcessEachMess age
      >Dim swLog As StreamWriter
      >>
      >swLog = New StreamWriter(sP ath & "\bestdesk\log\ RiskIn" &
      >Date.Now.ToStr ing("MMddyy") & ".txt", True)
      >swLog.Write(No w & "NEWTRADE sMessage = " & Message & vbCrLf)
      >swLog.Close( )
      >swLog = Nothing
      >:
      >>
      >
      >

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Error writing to a file

        It does not really remove something beside the reference to it.

        Cor

        "fniles" <fniles@pfmail. comschreef in bericht
        news:eUfMA4JmHH A.3264@TK2MSFTN GP04.phx.gbl...
        Thanks.
        What did you mean by ""Nothing" keyword is to set reference." ?
        >
        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:ujtByqJmHH A.4132@TK2MSFTN GP02.phx.gbl...
        >fliles,
        >>
        >I am not sure but in Net there is the magic word flush too.
        >>
        >http://msdn2.microsoft.com/en-us/lib...sh(VS.71).aspx
        >>
        >Be always aware that the "Nothing" keyword is to set reference. It has
        >nothing to do with the real object.
        >>
        >Cor
        >>
        >>
        >>
        >"fniles" <fniles@pfmail. comschreef in bericht
        >news:u%23WqgcJ mHHA.3888@TK2MS FTNGP05.phx.gbl ...
        >>For each message that my application receives I write it to a log file.
        >>Since each message is its own thread, many time I get the error "The
        >>process cannot access the file "c:\bestdesk\lo g\RiskIn051707. txt"
        >>because it is being used by another process." Is there a way to get
        >>around this error ? I can do the same thing in VB6 with no problem.
        >>Thank you.
        >>>
        >>This is how I write to the file:
        >>Sub ProcessEachMess age
        >>Dim swLog As StreamWriter
        >>>
        >>swLog = New StreamWriter(sP ath & "\bestdesk\log\ RiskIn" &
        >>Date.Now.ToSt ring("MMddyy") & ".txt", True)
        >>swLog.Write(N ow & "NEWTRADE sMessage = " & Message & vbCrLf)
        >>swLog.Close ()
        >>swLog = Nothing
        >>:
        >>>
        >>
        >>
        >
        >

        Comment

        Working...