Invalid mail attachment error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm developing a windows service that monitors a directory (using a
FileSystemWatcher) for newly created files. When a new file is created, I
need to generate an e-mail and send that file as an attachment. This all
working fine except that sometimes the code that adds the attachment fires
before the new file is finished being written to, resulting in an "invalid
mail attachment" error.

What is the best way to deal with this? Is there some way to determine if a
file is not being accessed before trying to attach it? Should I find some way
to delay the attachment by a few seconds? Thanks in advance for your help!

Brian
 
Why not just do this in error handling: if the file is being used, sleep for
a second.

--- N
 
That's exactly what I'm thinking, Nick...problem is I'm not sure how to go
about it. I obviously need to create some sort of object (File, FileInfo,
etc.) that has the ability to tell me if the file in question is in use, I
just haven't been able to find something that does that.
 
Back
Top