• Register
0 votes
71 views

Problem :

I have some of the code and when I try to executes it, it throws the below IOException, saying that

“The process cannot access the file 'filename' because it is being used by another process”

What is the meaning of this exception , and how can I completely fix the exception?

6 5 3
7,540 points

1 Answer

0 votes

Solution :

 

I had the below scenarios which was causing the similar error:

· While uploading files to the server

· While getting rid of my old files after they are uploaded to the server.

Most of the files were small in size, however, a few were very large, and so while attempting to delete my files resulted in cannot access file error.

It was not easy for me to find it, but the solution for it was as simple as Waiting "for my task to complete the execution":

using (var mywc = new WebClient())

{

  var mytskResult = mywc.UploadFileTaskAsync(_address, _fileName);

  mytskResult.Wait();

}

 

OR

I also had faced the same issue in the recent past while I was trying to upload my image and I couldn't delete it and found the solution later on it.

//The C# .NET
var myimage = Image.FromFile(filePath);

myimage.Dispose(); // this will remove all resources

//later on...

File.Delete(filePath); //now it works

 

9 7 4
38,600 points

Related questions

0 votes
1 answer 9 views
9 views
Is there any way to check if the file is in use??
asked Sep 8 Oscar909 460 points
0 votes
1 answer 103 views
103 views
Problem : I have received the following error message: The process cannot access the file because another process has locked a portion of the file Cannot open the disk 'C:\Users\t825665\VM's\VPC\Windows 10 x64.vmdk' or one of the snapshot disks it depends on. ... power on failed. Failed to start the virtual machine. I guess my virtual machine is not starting anymore. Any clue how to fix that?
asked Nov 21, 2019 peterlaw 6.9k points
0 votes
1 answer 79 views
79 views
Problem : I am facing error on below step objUDMCountryStandards.Country = txtMySearchCountry.Text.Trim() != string.Empty ? txtMySearchCountry.Text : null; in the get grid data throws error as below : “The calling thread cannot access this object because a different thread owns it.” Is there anything wrong with my code?
asked Jan 7 alecxe 7.5k points
1 vote
1 answer 32 views
32 views
Problem : In the following step objUDMCountryStandards.Country = txtSearchCountry.Text.Trim() != string.Empty ? txtSearchCountry.Text : null; in get grid data throws the exception as below : The calling thread cannot access this object because a different thread owns it. What is wrong in my code?
asked Dec 28, 2019 alecxe 7.5k points
0 votes
1 answer 66 views
66 views
Problem : I have recently installed a website on my local machine using IIS 7 successfully. But when I tried to deploy it on the live server, I got a following error: "The page cannot be displayed because an internal server error has occurred" Nothing else. Using a same IIS 7 on live and also set to have the Detailed errors in Error Pages module, but still getting a same. What can be the reason?
asked Jan 28 jwilliam 3.9k points