Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - File being used by another process
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

File being used by another process

 Post Reply Post Reply Page  <12
Author
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 9:57am

Maybe it is the cint command.

Gone..
Back to Top
Erik5150 View Drop Down
Newbie
Newbie
Avatar

Joined: 05 December 2003
Location: Mexico
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote Erik5150 Quote  Post ReplyReply Direct Link To This Post Posted: 05 December 2003 at 12:18pm

Im getting this error too

what I'm trying to do is:

Copy an archive from a source path to a dest. path
FileInfo FS = new FileInfo(source);
FS.CopyTo(dest,
true);

then, I got this error message when Im trying to Delete the Original File (the one in the source path).

File.Delete(source);

What I Did was to make a function that waits for exclusive access to the original file doing this:

private
void WaitForExclusiveAccess(string FullPath)
{while
(true){
try
{
FileStream fs = new FileStream(FullPath, FileMode.Open, FileAccess.Read,
FileShare.None);
fs.Close();
break;
}
catch
{Thread.Sleep(4);}

}

so the final code goes like this:

FileInfo FS = new FileInfo(source);
FS.CopyTo(dest,
true);
WaitForExclusiveAccess(source);
File.Delete(source);


but Im afraid this solution isnt just the best one because that Thread.Sleep(4); affects the Page performance.

any suggestions ?

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 05 December 2003 at 12:34pm

while i dont have the time to pick apart your code with a fine toothed comb right now, i can tell you what the fix is..

you don't have closure on some things.... when you create a file, make sure you close that process before doing something else.. etc

Contribute to the working anarchy we fondly call the Internet
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2003 at 7:38am
Yup, that's it. You can't delete or edit a file while a stream is still reading or writing it, or the connection is just open.
Gone..
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.