[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

The process cannot access the file because it is being used by another process...

Asked by sapbucket in .NET

Tags: access, file, cannot, used, another

Hi experts! I'm having a problem using a WebClient. It seems that I keep getting the old "process cannot access the file because it is being used by another process" excpetion. Somehow, my own code must be causing this problem, because even after a total reboot it has the same prob (ie no other executable is tying up the file that is needed).

Here is my code. I'm lazy - i put down debug points in the catch() blocks. I don't output anything to the screen. But you can see where it always "catches" by my comment.


try
                              {
                                    WebClient client = new WebClient();
                                    FileStream fileStream = new FileStream(tempFile,
                                          FileMode.Open,
                                          FileAccess.Read,
                                          FileShare.None);

                                    client.DownloadFile(ConnectString, tempFile);

                                    if (!fileStream.CanRead)
                                    {
                                          string fileName = fileStream.Name;
                                          fileStream.Close();
                                          fileStream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
                                    }

                                    StreamReader streamReader = new StreamReader(fileStream);

                                    fileStream.Close();
                                    fileStream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
                                    streamReader = new StreamReader(fileStream);

                                    string[] discreteInfo = null;

                                    while (streamReader.Peek() != -1)
                                    {
                                          string Info = streamReader.ReadLine();
                                          discreteInfo = delimitedInfo.Split(new char[1] {','});
                                    }

                                    hashTable.Add(symbol, discreteInfo);
                              }
                              catch(System.IO.IOException)
                              {
                                    ;
                              }
                              catch(System.Net.WebException)
                              {
                                    ; // debug point always stops here...
                              }
                              finally
                              {
                                    
                              }


Here is the error message output:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.IOException: The process cannot access the file "C:\DOCUME~1\Owner\LOCALS~1\Temp\tmp4E.tmp" because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at System.Net.WebClient.DownloadFile(String address, String fileName)
   --- End of inner exception stack trace ---
 


Could this be solved with .dispose() or using()? I havent ever used those before.

Anyway, I'm stuck on this problem and could use some expert advice. Many thanks for your suggestions!

[+][-]01/30/06 04:15 PM, ID: 15829556Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: .NET
Tags: access, file, cannot, used, another
Sign Up Now!
Solution Provided By: TitoPeru
Participating Experts: 3
Solution Grade: A
 
[+][-]01/30/06 11:19 AM, ID: 15826549Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/30/06 11:27 AM, ID: 15826638Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/06 11:27 AM, ID: 15826653Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/30/06 11:32 AM, ID: 15826700Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/30/06 11:38 AM, ID: 15826761Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/30/06 12:13 PM, ID: 15827155Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/06 05:10 PM, ID: 15829813Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93