I am working on an C# application which creates a text file with some data in it, saves it in a folder, sends it to a list of email addresses and deletes the file from that location but when I call the File.Delete() it throws me an exception saying file cannot be accessed as it is being used by another process. That is because the file is being used by the email service and trying to delete so, its an obvious exception but when I tried to a Delay between two function calls, it still threw me an exception
_dailyBargainReport.sendRejectionReport(servername, fromAddress, password, sub, bodyofmail, rejectionReportPath);
Task.Delay(20000);
File.Delete(rejectionReportPath);