Kreij
Senior Monkey Moderator
- Joined
- Feb 6, 2007
- Messages
- 13,817 (2.20/day)
- Location
- Cheeseland (Wisconsin, USA)
I create a file on disk from my app, and then I want to send the file via e-mail.
This works fine by creating an SmtpClient and using the Send() method.
When the send completed I want to delete the file as there is no reason to save it any longer.
The Send() method is supposed to block until finished, but this throws a "File in use by another process" exception on the Delete method.
So I then tried running the whole thing in a BackgroundWorker and then doing the file delete in the RunWorkerCompleted event. This too throws the same error.
It's seems that SmtpClient process still has a handle attached to the thread, but I'm not sure why it is not letting it go when it's done with the send.
Any ideas?
Oops .. title was supposed to be SmtpClient not StmpClient.
This works fine by creating an SmtpClient and using the Send() method.
When the send completed I want to delete the file as there is no reason to save it any longer.
Code:
.... Code for creating file
SmtpClient _Client = new SmtpClient();
.... code for client configuration
try
{
_Client.Send(myFile);
}
catch()
{
... handle an exception
}
System.IO.File.Delete(myFile);
The Send() method is supposed to block until finished, but this throws a "File in use by another process" exception on the Delete method.
So I then tried running the whole thing in a BackgroundWorker and then doing the file delete in the RunWorkerCompleted event. This too throws the same error.
It's seems that SmtpClient process still has a handle attached to the thread, but I'm not sure why it is not letting it go when it's done with the send.
Any ideas?
Oops .. title was supposed to be SmtpClient not StmpClient.
Last edited: