Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to know whether a file is copied or not

How to know whether a file is copied or not

Scheduled Pinned Locked Moved C#
helptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DownBySpj
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • D DownBySpj

      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

      L Offline
      L Offline
      luckykhalid
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups