Accessing a file, that another process has open..

N

Newbie

Hi,

I have a situation where my application is trying to access a file, that
another application may have temporalily open.

The error I get is

The process cannot access the file 'C:\picks\test50k.gp1' because it is
being used by another process.


Is there a way I can loop in my program, some how testing if my app can
access the file, and then break out of the loop only when I can open the
file.

That way if another application has the file, I my app can wait till it is
finished.

Thanks
 
S

SuNcO

You can catch the error with something like this

Try
' open the file
Catch ex As IOException
MsgBox(ex.Message)
End Try

Instead of the MsgBox you can start a loop and a timer.. the timer is going
to check every 1 second if the file is still in use. When not, then you set
a variable that exits the loop

Hope this trick helps you
 
C

Chris Dunaway

I have a situation where my application is trying to access a file, that
another application may have temporalily open.

The error I get is

The process cannot access the file 'C:\picks\test50k.gp1' because it is
being used by another process.

What code did you use to try to open the file? Did you specify a
sharing mode? If the other program has not opened the file
exclusively then you should be able to open the file at the same
time. Do you intend to modify the file? Or just read it? Some more
details would make it easier to help you.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top