Re: FileSystemWatcher and Getting Access to a file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: gregory_may (None)
Date: 08/02/04


Date: Mon, 2 Aug 2004 09:18:37 -0700

I will past the text from the link -
http://www.dotnet247.com/247reference/msgs/29/146407.aspx:
I am having the same problem. Is there a better solution????:

----
      I am trying to use the System.IO.FileSystemWatcher class
      to watch for new files in a directory. The problem I'm
      having is that it seems the 'oncreate' event fires before
      the new file is completely written. Therefore when I try
      to do anything with the file (such as copy the file to
      another directory) I get an error message along the lines
      of "The process cannot access the file because it is being
      used by another process." The only solution I've found is
      to catch this exception and just keep trying to process
      the file until the exception goes away. This solution
      isn't working well and it seems there has to be a better
      way to solve this problem. Has anyone found a better
      solution to this?
      Thanks in advance for any advice.
           Reply to this message...
           prowler
            I faced the exact same issue and made a workaround by
            trying to continually open the file with FileShare.None,
            and ignoring a particular exception. Once this succeeds I
            proceed further. The files I was dealing with could take
            several minutes to come in. Fortunately the app is not
            extremely performance intensive and I can do a
            Thread.Sleep for a minute and check back.
            I was wishing there was amore elegant way to deal wth
            this. Would like to find out.
            -prowler
"Lebrun Thomas" <lebrun.thomas@wanadoo.fr> wrote in message
news:eEejMTldEHA.3420@TK2MSFTNGP12.phx.gbl...
> > Does anyone have a more
> > elegant solution to this problem rather than just "trying to continually
> > open the file with FileShare.None, and ignoring a particular
exception"??
>
> Yes : find why the file could not be access :)
> Which proces can use it ?
>
> --
> LEBRUN Thomas
> http://morpheus.developpez.com
>
>
> "gregory_may" <None> wrote in message
> news:uGB5hXbdEHA.1652@TK2MSFTNGP09.phx.gbl...
> > http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/default.aspx
> >
> >
> > Hi,
> >
> > I have created a batch file router using the filesystemwatcher
componant.
> I
> > am facing the exact same issue as the link above.  Does anyone have a
more
> > elegant solution to this problem rather than just "trying to continually
> > open the file with FileShare.None, and ignoring a particular
exception"??
> >
> >
> > Thanks!!!
> >
> >
>
>
begin 666 r.gif
M1TE&.#EA$ `0`(<``& @8& @<' H<( X@(!(D)! D)! H)!(H(=_M*!(L*!0
MH*!0L*!8L+!0L*!HL+!@L+!HL+!8P+!PP+!XP,!HP("(L):/M("(P("0P("0
MT)"0P):6PY"8P)"8T)VDQY"@T*"8P*6EPZ2DRZ"HP*"@T*"HT*"PT+"XT+#8
M\+#@_[#H_\" P," T,"(T-"8T-"@T-"HT/#0@/#8@/#0D/_@@/_H@/_@D/_H
MD/_HH/_HL/#PH/_PH/_PL/_XL,# T,# X,#8\,#@_\#H\,#H_]#P_^#0P.35
MY/_XP/__P/__T./E[^WB[>#H\.#H_^KJ\.KK\^WN]N#P\.#P_^#X_^#_____
MX/#P]O#P__#X__#_____\/___P``````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````"'Y! ```/\`+ `````0`! ```C%`+<('$BP($$H
M'D*$X,!!B4&!4$1HF5BE!X(G!B-.W*(E28\;")P<]%"E"L4C.VK0L&!E8 D<
M,''8L"$CALT9&UR:0(*D1P\>.6#F\#'"I9 ..CZ4,''B1!$?$$X,_$ %!8DH
M4[!<8?)#@@&I`CNHZ! ERY2S32:\. #A`8,$'#)(P7)V"I,),%RT8+%B@@`-
M0(@,29$BB(,7+"A$:+# 0 `,D"]<J* !! $%$18D*# `P,,M1@(8`$":].<M
*2TR?)IB:8$ `.P``
`
end


Relevant Pages

  • Re: FileSystemWatcher and Getting Access to a file
    ... > elegant solution to this problem rather than just "trying to continually ... > open the file with FileShare.None, and ignoring a particular exception"?? ... > am facing the exact same issue as the link above. ...
    (microsoft.public.dotnet.framework)
  • __init__, __slot__ and **keywordargs
    ... I want the arguments of __init__ to be keywords and that the ... method initialize all the attributes in __slot__ to None except those ... not in the slot and i want to have an exception when someone tries to ... Someone knows a more elegant solution and can ...
    (comp.lang.python)
  • Re: Overriden method doesnt throw Exception, super may.
    ... >> haven't been ignoring you, I've actually been trying to understand the ... idea of ignoring the exception, and then try to blast me for it? ... is, as has been pointed out, the exception is NEVER thrown because the ... Converting to a runtime exception is just as bad an idea here as ignoring ...
    (comp.lang.java.programmer)
  • Re: Only writing 1 byte to a file stream on one pc in office
    ... The OP has a finally block, not catch, so he isn't ignoring anything. ... His application-level exception handler will log any exception... ... checking his file cache I found that most of the files were only 1 byte ... FileStream fs = new FileStream(ImageLocation, FileMode.Create, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange Audio Problem
    ... >Perhaps it is throwing an exception the code is ignoring. ... Exception and stacktraces them all just to be sure that it isn't the ... Could it be something else than an infinite loop? ... And the server and the test-program both runs on the same machine under ...
    (comp.lang.java.programmer)