File Locking Question

G

Guest

I'm writing a WinForms app that copies files to Pocket PC using the RAPI
'CopyFileToDevice' method. If there are no interruptions then everything
works perfectly.

But in testing, I've deliberately disconnected the Pocket PC to see what
happens.

Upon reconnection I get an error that the source file is being used by
another process - in other words, the file is locked.

Since I know the previous process has concluded, is there a way for me to
forcibly unlock the file?
 
W

W.G. Ryan eMVP

AFAIK, there's no easy way around this - pulling the cable while syncing
sucks - BAD. Let me look around for you but typically it's going to be a
mess if it happens.

W.G. Ryan MVP
Windows Embedded
 
G

Guest

Here's one approach I'm considering. What do you think:

When I startup the WinForms app I can ensure that there's a temporary
subfolder, like: C:\Temp\AppName I will try to erase all files in it.

When it's time to copy a file to a mobile device I can first use File.Copy
to copy the source file (which seems to work regardless if there's a lock)
into this folder. And if the file already exists, perhaps from a previous
lock, then I'd just add a numeric digit to it until I found a free filename -
like "Filename1.ext", "Filename2.ext", etc.

And then this copy, which I'll know is not locked, I can copy to the mobile
device.

Comments appreciated.
 

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