How to know whether a file is copied or not
-
I am working on creating a windows service. Here I have to watch a folder for any file that is placed in that folder. If a file is placed in that folder i have to process it. I am doing this with the filesystemwatcher component's created method. This works fine when i am placing files one by one. But when i place 5 or 6 files at the same time, or when i place a file of bigger size, say above 3 MB, it produces error, saying that the an system.ioexception has occurred. The file is being used by another application. I think this is due to the fact that the windows takes some time to copy that file to that folder, whereas filesystemwatcher components starts it's execution as soon as it finds a file in that folder. Any suggestion will be very welcome
-
I am working on creating a windows service. Here I have to watch a folder for any file that is placed in that folder. If a file is placed in that folder i have to process it. I am doing this with the filesystemwatcher component's created method. This works fine when i am placing files one by one. But when i place 5 or 6 files at the same time, or when i place a file of bigger size, say above 3 MB, it produces error, saying that the an system.ioexception has occurred. The file is being used by another application. I think this is due to the fact that the windows takes some time to copy that file to that folder, whereas filesystemwatcher components starts it's execution as soon as it finds a file in that folder. Any suggestion will be very welcome
Hi Create a seperate thread in which you will process that file. For instance, if you have 5 files moved into the folder, you will be having 5 threads that would process those files. In every thread, make a variable that would be having state of the file. whenever a file is copied into the filesystem, filesystemwatcher trigers Created event once and then Changed event twice. When the Chnaged event is fired for the same file for the second time then start doing anythng on that file. Hope it helps
Regards Khalid