Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.killfile.org!.POSTED!not-for-mail From: CarolHudson Newsgroups: comp.programming Subject: Re: c# .net 4 unable to move file - file in use by another process (by itself) Date: Wed, 22 Apr 2015 21:05:16 +0200 Organization: Killfiles, Unlimited Lines: 12 Message-ID: References: <4c284fb9-3878-43e0-9d11-85b7c33ce269@googlegroups.com> <54fe757c-e9cb-498f-8a01-6da94ee73537@googlegroups.com> NNTP-Posting-Host: p5b342eaa.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: flea.killfile.org 1429729516 29935 91.52.46.170 (22 Apr 2015 19:05:16 GMT) X-Complaints-To: news@usenet.killfile.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 In-Reply-To: Xref: csiph.com comp.programming:5410 On 25.03.2015 01:09, Julio Di Egidio wrote: > On Tuesday, March 24, 2015 at 7:12:17 PM UTC, Justin Marshall wrote: > >> Well we eventually identified root cause, it was in a completely unrelated section of code (error notification). it appears the SMTP class requires that you explicitly close the attachments once you are done, if you don't it will hang onto them indefinitely even after the class that instantiated them terminates. > > In .NET 4, SmtpClient, AttachmentBase, MailMessage, and other classes from the System.Net.Mail namespace implement the IDisposable interface (check the docs). To correctly use classes that implement IDisposable, you should use the "disposable patter" (the using statement), and, if appropriate, you can encapsulate the whole thing in a custom class of yours that itself implements IDisposable. > > HTH, > > Julio > Julio, you are blind, you are a moron, that's not how it works!