My guess would be that the mail message has opened the file, but
doesn't close it until it get's disposed. The System.Web.MailMessage
doesn't provide any way to explicitly do that.

try the System.Net.Mail API.
System.Net.Mail.MailMessage has a dispose method, this will assure you
that any resources used by the mail message will be released.
The System.Web.Mail API recommends using the other newer API.

Also, it is not explicitly stated in the documentation, but normally
method that have "Async" in the name are synchronous. So that leads me
to believe SmtpMail.Send() method is synchronous, therefore the
sending of the message it complete when the method returns, you
shouldn't need the Thread.Sleep().

On Sep 2, 11:16 am, JaffaB <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I have a server based application which sends out emails with file
> attachments.  The problem I have is, that when I save the files in a
> temp store to send them as attachments, and then try and delete them,
> I get an exception error.
>
> My code is currently as follows:
>
>             SmtpMail.Send(MailMsg)
>             System.Threading.Thread.Sleep(1000)
>             '
>             '   Clear down the temp attachments
>             '
>             For Inc As Integer = 0 To AttachmentList.Count - 1
>                 If File.Exists(AttachmentList(Inc)) Then
>                     File.Delete(AttachmentList(Inc))
>                 End If
>             Next Inc
>
> And when it gets to the deletion of the files, I get the file in use
> exception…
>
> Error occured as exception :- The process cannot access the file 'C:
> \WINDOWS\system32\MyApp\Temp\TestDoc.doc' because it is being used by
> another process. In MyApp Service
>
> As you can see, I have already tried the (crude) sleep option, but I
> believe the MAIL.SEND is just queuing the mail up, and whatever thread
> is then spawned still needs the attachment.
>
> What I really need is for send to wait to be completed before the code
> continues, so the file is released and I can delete it.  Otherwise, I
> am going to fill up my disk with thousands of temp files.
>
> Any ideas would be appreciated
>
> Jaffa

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to