Advertisement

01.30.2006 at 10:41AM PST, ID: 21715816
[x]
Attachment Details

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!

Start Free Trial
[+][-]01.30.2006 at 11:19AM PST, ID: 15826549

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 11:27AM PST, ID: 15826638

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 11:27AM PST, ID: 15826653

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 11:32AM PST, ID: 15826700

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 11:38AM PST, ID: 15826761

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 12:13PM PST, ID: 15827155

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 04:15PM PST, ID: 15829556

View this solution now by starting your 7-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.2006 at 05:10PM PST, ID: 15829813

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32