|
-
May 22nd, 2013, 08:25 PM
#1
Thread Starter
Lively Member
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.
-
May 22nd, 2013, 08:46 PM
#2
Thread Starter
Lively Member
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.
-
May 22nd, 2013, 08:49 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|