Results 1 to 3 of 3

Thread: File Used by Another Process (Timer)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    78

    File Used by Another Process (Timer)

    Hey Everyone -

    I have a little snag. I have this code on a timer
    Code:
     My.Computer.FileSystem.WriteAllText("C:\test\jesterlog.txt", tbLog.Text, True)
    . It runs fine the first time, but when the timer ticks the second time I get the error "The process cannot access the file 'C:\test\jesterlog.txt' because it is being used by another process." Is there a simple way to just close the file? This seems very simple but I'm not seeing a clear cut way to just dispose or close the file. Thanks!
    Last edited by WRCREX; May 22nd, 2013 at 08:34 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    78

    Re: File Used by Another Process (Timer)

    Also, according to MSDN using writealltext is supposed to close the file after it's written to. There are no other areas of the program dealing with this file.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: File Used by Another Process (Timer)

    Would it make sense to just close the file when you have no idea what process is using it and what it's using it for? Who knows what the results might be.

    What you should be doing is determining why it's open. Are you opening it in another application? If not then you are presumably opening it the code of this application and not closing it. In that case you need to identify where that's happening and fix it, most likely by closing the file there, where it's opened after it has been used for whatever it's used for. Do that and your original problem goes away. Deal with the cause, not the symptoms.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width