Re: error creating/writing to log file...strange problem!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Milsnips (milsnips_at_hotmail.com)
Date: 02/07/05


Date: Mon, 7 Feb 2005 12:19:36 +0100

this is the code i was using....

If Not IO.File.Exists(AppPath & "\log.txt") Then IO.File.Create(AppPath &
"\log.txt")
Dim f As IO.StreamWriter = IO.File.AppendText(AppPath & "\log.txt")

it crashes on the second line.

regards,
Paul

"Doug Forster" <doug_ZAPTHIS_AT_ZAPTHIS_TONIQ_DOT_CO_DOT_NZ> wrote in
message news:OsDCNZiCFHA.1188@tk2msftngp13.phx.gbl...
> Hi,
>
> You seem to think that there is a timing issue involved. This is most
> unlikely. The file will have been locked because your code left it locked.
> i.e. you failed to close the file. Though you have solved your problem you
> need to show us some code if you want to know why you have solved it.
>
> Cheers
>
> Doug Forster
>
> "Milsnips" <milsnips@hotmail.com> wrote in message
> news:e8hwVOfCFHA.1396@TK2MSFTNGP14.phx.gbl...
>> yes thats the problem.. i moved the code to create the log file at
>> opening the app, and problem doesnt appear anymore.
>>
>> Is there anyway that i could make it wait until the process has unlocked
>> the file and then continue?
>> thanks,
>>
>> Paul
>> "Peter Foot [MVP]" <feedback@nospam-inthehand.com> wrote in message
>> news:uVQjlLfCFHA.3732@TK2MSFTNGP14.phx.gbl...
>>> Can you post a code snippet showing the problem? The exception is most
>>> likely if the file is still locked when you try to open it.
>>>
>>> Peter
>>>
>>> --
>>> Peter Foot
>>> Windows Embedded MVP
>>> www.inthehand.com | www.opennetcf.org
>>>
>>> "Milsnips" <milsnips@hotmail.com> wrote in message
>>> news:O34kAkeCFHA.2620@tk2msftngp13.phx.gbl...
>>>>i have a function that checks for a log file, if not exists then it
>>>>creates
>>>> it, then opens it and writes a error log.
>>>>
>>>> the problem is, first time it calls the event and the file does not
>>>> exist,
>>>> it creates it okay, but when it tries to open it straight after that,
>>>> it
>>>> throws an IOException.
>>>> If i close the app, then re-open and add another log to the existing
>>>> file,
>>>> it works okay??
>>>>
>>>> any help appreciated,
>>>>
>>>> thanks,
>>>> Paul
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Relevant Pages

  • Re: MSAccess to Web App
    ... Regards your comments on who owns your financial data, ... our PC-based app, for example, there are a number of ways that a user ... have to continue to support the legacy app for some time to come. ... Online banking is really not in any way analogous to what you're ...
    (comp.databases.ms-access)
  • Switching for COInitialize to OleInitialize crashes app
    ... A simple WTL SDI app with the following helper class crashes after a switch ... from CoInitialize and CoUnitialize to OleInitialize and OleUninit.... ... then it doesn't crash. ...
    (microsoft.public.vc.atl)
  • Re: PictureBox1 GDI+ error
    ... Besides the picturebox there are only a few labels on the ... The application NEVER crashes in the IDE running on Windows XP ... including the one that hosts VS 2005 and that is used to develop the app. ... Dim WebClient As New System.Net.WebClient ...
    (microsoft.public.vb.general.discussion)
  • Re: [Announce] 2.6.29-rt1
    ... I've got crashes when I run an app with thread with RT priority. ... This crash could happen on any comman, ... and after just run a simple "ifconfig" ...
    (Linux-Kernel)
  • Re: Vista Media Center Crash
    ... Either the component that raises this event is not installed on your local computer or the installation is corrupted. ... P4: unknown ... it immediately crashes and sends a ...
    (microsoft.public.windows.mediacenter)