C# and unable to close pdf Files methods Load() & Dispose()
I have a list of pdf files in my listBox, I want to use dispose() to release ressources of the system and delete my pdf files in my directory. but I can not and it throw me an exception when I load the file
An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in AxInterop.AcroPDFLib.dll
Additional information: COM object that has been separated from its underlying RCW cannot be used.
void MonMouseClick(object sender, MouseEventArgs e)
{
if (lstDoc.SelectedItem != null)
{
axAcroPDF.LoadFile(lstDoc.SelectedItem.ToString());
}
}
void DeleteFiles(string Rep)
{
axAcroPDF.Dispose();
Array.ForEach(Directory.GetFiles(Rep), File.Delete);
}
private void Form1_Load(object sender, EventArgs e)
{
DeleteFiles(@"c:\\Temp2");
}
Please Any Help Or Suggestions! Thanks!