C# – The process cannot access the file because it is being used by another process

c

I have a set of nightly reports.

Sometimes I get the exception:

The process cannot access the file because it is being used by another process

How do I tell what process is holding on to the file? I am thinking that it is McAfee but I need to prove it.

Best Answer

The problem was the MailMessage in .NET was holding on to the file attachments. I had to do a dispose on the attachment and then it worked.