File locked after sending it as attachment

前端 未结 6 1437
-上瘾入骨i
-上瘾入骨i 2020-12-10 13:20

I am sending a file as an attachment:

            // Create  the file attachment for this e-mail message.
            Attachment data = new Attachment(filePa         


        
6条回答
  •  孤城傲影
    2020-12-10 13:29

    You need to take advantage of "using" keyword:

    using(Attachment att = new Attachment(...))
    {
       ...
    }
    

    That's because "using" ensures IDisposable.Dispose method is called at the end of code block execution.

    Whenever you use some class that's managing some resource, check if it's IDisposable and then use "using" block and you won't need to care about manually disposing calling IDisposable.Dispose.

提交回复
热议问题