C# move file as soon as it becomes available.

Posted by m0s on Stack Overflow See other posts from Stack Overflow or by m0s
Published on 2010-04-27T08:46:43Z Indexed on 2010/04/27 8:53 UTC
Read the original article Hit count: 192

Filed under:
|
|

Hi,

I need to accomplish the following task:

Attempt to move a file. If file is locked schedule for moving as soon as it becomes available.

I am using File.Move which is sufficient for my program. Now the problems are that:

1) I can't find a good way to check if the file I need to move is locked. I am catching System.IO.IOException but reading other posts around I discovered that the same exception may be thrown for different reasons as well.

2) Determining when the file gets unlocked. One way of doing this is probably using a timer/thread and checking the scheduled files lets say every 30 seconds and attempting to move them. But I hope there is a better way using FileSystemWatcher.

This is a .net 3.5 winforms application. Any comments/suggestions are appreciated. Thanks for attention.

© Stack Overflow or respective owner

Related posts about c#

Related posts about io