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. Connection Not Closing File.Move

Connection Not Closing File.Move

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 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.
  • K Offline
    K Offline
    kornstyle
    wrote on last edited by
    #1

    Hi. I'm using the "File.Move" method in the System.IO namespace. When I start my program and call this method it executes no problem. The second time I call it I am getting and error message saying "Exception: The process cannot access the file ... because it is being used by another process". When I close the program and run it again the method runs fine, again for the first time. I would think the connection is just not closing for some reason. Does anyone know how I can fix this?

    P D 2 Replies Last reply
    0
    • K kornstyle

      Hi. I'm using the "File.Move" method in the System.IO namespace. When I start my program and call this method it executes no problem. The second time I call it I am getting and error message saying "Exception: The process cannot access the file ... because it is being used by another process". When I close the program and run it again the method runs fine, again for the first time. I would think the connection is just not closing for some reason. Does anyone know how I can fix this?

      P Offline
      P Offline
      Peter Vertes
      wrote on last edited by
      #2

      Well, you could try calling dispose() on your object to see if it would help. My guess is your problem is somewhere else. Are you using any FileStreams ? You definately need to close those by explicitly calling Close() on them. Post some more code if you can... -Peter

      1 Reply Last reply
      0
      • K kornstyle

        Hi. I'm using the "File.Move" method in the System.IO namespace. When I start my program and call this method it executes no problem. The second time I call it I am getting and error message saying "Exception: The process cannot access the file ... because it is being used by another process". When I close the program and run it again the method runs fine, again for the first time. I would think the connection is just not closing for some reason. Does anyone know how I can fix this?

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Not enough information. Move what file? Is your application writing it? Are you holding it open? Where does this file come from that your trying to move? The problem is obvious - "being used by another process". This means that you can't move a file that is open for reading and/or writing. So what has the file open? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        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