File Locking Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert W.

    File Locking Question

    I'm writing a WinForms app that copies files to Pocket PC using the RAPI
    'CopyFileToDevi ce' method. If there are no interruptions then everything
    works perfectly.

    But in testing, I've deliberately disconnected the Pocket PC to see what
    happens.

    Upon reconnection I get an error that the source file is being used by
    another process - in other words, the file is locked.

    Since I know the previous process has concluded, is there a way for me to
    forcibly unlock the file?

    --
    Robert W.
    Vancouver, BC


  • W.G. Ryan eMVP

    #2
    Re: File Locking Question

    AFAIK, there's no easy way around this - pulling the cable while syncing
    sucks - BAD. Let me look around for you but typically it's going to be a
    mess if it happens.

    W.G. Ryan MVP
    Windows Embedded
    "Robert W." <RobertW@discus sions.microsoft .com> wrote in message
    news:1624FC2C-9381-4388-9FC6-0DF778927E31@mi crosoft.com...[color=blue]
    > I'm writing a WinForms app that copies files to Pocket PC using the RAPI
    > 'CopyFileToDevi ce' method. If there are no interruptions then everything
    > works perfectly.
    >
    > But in testing, I've deliberately disconnected the Pocket PC to see what
    > happens.
    >
    > Upon reconnection I get an error that the source file is being used by
    > another process - in other words, the file is locked.
    >
    > Since I know the previous process has concluded, is there a way for me to
    > forcibly unlock the file?
    >
    > --
    > Robert W.
    > Vancouver, BC
    > www.mwtech.com
    >[/color]


    Comment

    • Robert W.

      #3
      Re: File Locking Question

      Here's one approach I'm considering. What do you think:

      When I startup the WinForms app I can ensure that there's a temporary
      subfolder, like: C:\Temp\AppName I will try to erase all files in it.

      When it's time to copy a file to a mobile device I can first use File.Copy
      to copy the source file (which seems to work regardless if there's a lock)
      into this folder. And if the file already exists, perhaps from a previous
      lock, then I'd just add a numeric digit to it until I found a free filename -
      like "Filename1.ext" , "Filename2.ext" , etc.

      And then this copy, which I'll know is not locked, I can copy to the mobile
      device.

      Comments appreciated.

      --
      Robert W.
      Vancouver, BC




      "W.G. Ryan eMVP" wrote:
      [color=blue]
      > AFAIK, there's no easy way around this - pulling the cable while syncing
      > sucks - BAD. Let me look around for you but typically it's going to be a
      > mess if it happens.
      >
      > W.G. Ryan MVP
      > Windows Embedded
      > "Robert W." <RobertW@discus sions.microsoft .com> wrote in message
      > news:1624FC2C-9381-4388-9FC6-0DF778927E31@mi crosoft.com...[color=green]
      > > I'm writing a WinForms app that copies files to Pocket PC using the RAPI
      > > 'CopyFileToDevi ce' method. If there are no interruptions then everything
      > > works perfectly.
      > >
      > > But in testing, I've deliberately disconnected the Pocket PC to see what
      > > happens.
      > >
      > > Upon reconnection I get an error that the source file is being used by
      > > another process - in other words, the file is locked.
      > >
      > > Since I know the previous process has concluded, is there a way for me to
      > > forcibly unlock the file?
      > >
      > > --
      > > Robert W.
      > > Vancouver, BC
      > > www.mwtech.com
      > >[/color]
      >
      >
      >[/color]

      Comment

      Working...