I found the problem.
The file was an image: the was caused by the missing Dispose() of the image after the Image.LoadFromFile().
Thanks anyway.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi all,
I'm writing a WinForm C# program that watches a folder by a FileSystemWatcher.
When a file (4kb) arrives in that folder I copy it in two other foldes: so far I achieve that by File.Copy() then File.Move() calls.
On the Move() call I always have an IoException: File in use from other process.
The operation is done on a control.Invoke() function, here I added a secondary thread and in plus I separated Copy and Move calls with a Sleep(1000).
Nothing to do, always IoException.
The Copy operation is synchronous, is it?
By some Console.Write() calls I see that the filesystemWatcher funtion is done when the Move function is invoked ..
How can I solve?
Which process is using the file?
Thanks, regards
I found the problem.
The file was an image: the was caused by the missing Dispose() of the image after the Image.LoadFromFile().
Thanks anyway.
To rule out Copy method being the issue try the following.
public static async Task CopyFileAsync(string sourceFile, string endDirectory)
{
await using FileStream sourceStream = File.Open(sourceFile, FileMode.Open);
await using FileStream destinationStream = File.Create(
Path.Combine(endDirectory, Path.GetFileName(sourceFile)));
await sourceStream.CopyToAsync(destinationStream);
}