Re: How to check if a file is locked?

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am not sure of the relevance of the first post on here perhaps it went to
the wrong thread?

For file locking you would have to handle this exception anyways. The file
may not be locked when you check it but could then be locked when you try to
go to open it. The checking would however remove many instances of ther
exception. That said in this case your best best is to trap the exception as
there is no other good way of doing this, you could also use pinvoke
(CreateFile) to avoid having the exception thrown but the exception is
really not that expensive. You should then wait a little bit before trying
again if thats your overall goal.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung


"cmay" <cmay@xxxxxxxxxxxxxx> wrote in message
news:1152216505.981826.103000@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The only examples I have seen on how to check if a file is locked is to
try to open it a catch an exception.

MS has stated that you should never use error trapping in this manner.

Is there no other way to identify if a file is locked w/o trapping an
exception?



.



Relevant Pages

  • How to check if a file is locked?
    ... try to open it a catch an exception. ... MS has stated that you should never use error trapping in this manner. ... Is there no other way to identify if a file is locked w/o trapping an ...
    (microsoft.public.dotnet.general)
  • Re: weird ACCDDS.DLL error
    ... After reviewing your first post, ... connectMode, object addInInst, ref System.Array custom) ... It pops up the exactly same exception message as you post: ... Could not load file or assembly ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: How to get most info from exception
    ... Ok Jonah, I got you now. ... Your first post didn't really say that the errors ... > every now and then through emails using a function with GetLastError ... >> line raised the exception. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Interpretting the symbols (WinDbg)
    ... My first post was in the programmer.kernel NG. ... I was testing a VB application that hosts a server control (ATL). ... First chance exceptions are reported before any exception handling. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Interpretting the symbols (WinDbg)
    ... My first post was in the programmer.kernel NG. ... I was testing a VB application that hosts a server control (ATL). ... First chance exceptions are reported before any exception handling. ...
    (microsoft.public.vc.atl)