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. "This file is being used by another process", can I know the name of process?

"This file is being used by another process", can I know the name of process?

Scheduled Pinned Locked Moved C#
csharpjsonquestion
4 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.
  • A Offline
    A Offline
    abcxyz82
    wrote on last edited by
    #1

    My winform application(C#) needs to delete a file, I have set all references to that file in my code with null and then I use File.Delete..Catching exception sometimes shows - "this file is being used by another process".. Is there any API by which we can know who has locked the file handles and if thers any sharing violation...so my application can show a cute message saying :((XYZ file is being used application :((APP Do tell me if I need to configure any CASPOL settings..

    C 1 Reply Last reply
    0
    • A abcxyz82

      My winform application(C#) needs to delete a file, I have set all references to that file in my code with null and then I use File.Delete..Catching exception sometimes shows - "this file is being used by another process".. Is there any API by which we can know who has locked the file handles and if thers any sharing violation...so my application can show a cute message saying :((XYZ file is being used application :((APP Do tell me if I need to configure any CASPOL settings..

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      abcxyz82 wrote: I have set all references to that file in my code with null Did you actually Close() the file before you set the reference to null?


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      A 1 Reply Last reply
      0
      • C Colin Angus Mackay

        abcxyz82 wrote: I have set all references to that file in my code with null Did you actually Close() the file before you set the reference to null?


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        A Offline
        A Offline
        abcxyz82
        wrote on last edited by
        #3

        Actually my application loads image from the file name in some controls and saves image in business object...and I remove trace of that image file from all placess(removing from control,setting null in business object)..etc.. REgards MaulikCE

        D 1 Reply Last reply
        0
        • A abcxyz82

          Actually my application loads image from the file name in some controls and saves image in business object...and I remove trace of that image file from all placess(removing from control,setting null in business object)..etc.. REgards MaulikCE

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

          Colin's question still stands. Did you close the file before you set the object you used to null. If not, and even if you dropped your reference to the stream object, the underlying unmanaged file handle is not released until you either call the Close() method or the Garbage Collector gets around to calling the objects .Dispose() method. Until one of those two things happens, the underlying file handle will remain OPEN and, hence, sitll in use by another application, specifically, yours. 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