smtp.attachment lockes file when send exception.

  • Thread starter Thread starter Kees
  • Start date Start date
K

Kees

Hi there,

Im having a bit of trouble with a logfile I use to put logevents in with a
streamwriter, after I have written in this file I want to send the file as a
mailattachment with smtp.
This all works fine until the smtp server goes off line or something goes
wrong.
I'm then catching the 'Mail.Send' exception.

Now there is the problem. The log file I tried to send is now locked so when
the
streamwriter wants to write a line in the file, streamwriter throws me an
exception.
'file is in use by an other process'
the file is now locked and will only unlock when the mail is send (without
exception) or when i kill the app.

Why is it locked, or better, how do I get it unlocked?

Anyone?
//////////////////////////////////////////////////////////////
Try

SmtpMail.SmtpServer = SmtpServer

SmtpMail.Send(MyMail)

Catch ex As Exception

' Now the file is
locked

Return ex.Message

End Try
//////////////////////////////////////////////////////////////
 
Hi Kees,

Why not simple copy the file before you bring it to the Smtp.

Than both processes are independent from each other.

You even can make a test in the making process if the old file is already
processed.

I think that is even as a solution much nicer.

I hope this helps?

Cor
 
Back
Top