system.net.mail deleting temp file

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

Hi

I copy my application log file to the temp directory and send this using a
System.Net.Mail.SmtpClient as an attachment.
I need to delete this file afterwards but I'm getting an error that the file
is in use. I assume that smtpclient is sending the email asynchronously, and
that's why I get the error, but I'm not sure.
What do i do to delete this file please?

thank you
 
Hi Claire,
I assume that smtpclient is sending
the email asynchronously

Well, you can check, right; which method are you using:

System.Net.Mail.SmtpClient.Send() // or
System.Net.Mail.SmtpClient.SendAsync() // ?

If you are using the latter, and want to check whether that's the
problem, you could let the thread that deletes the file sleep for a
bit until the asynchronous sending of e-mail has been completed.

If that doesn't solve a problem, post a short-but-complete (;-))
program that reproduces the problem.

Regards,
Jeroen
 
Hi

I copy my application log file to the temp directory and send this using a
System.Net.Mail.SmtpClient as an attachment.
I need to delete this file afterwards but I'm getting an error that the file
is in use. I assume that smtpclient is sending the email asynchronously, and
that's why I get the error, but I'm not sure.
What do i do to delete this file please?

thank you

Hi Claire,

Make sure you dispose of the mail object and the smtpclient when you're
done. It has been known to help in many cases
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top