I am currently writing an app that exports certain data areas of some Excel files as image files to an image folder and then displays them. The program should also be able to update all files (including these) during the display of a file.
Problem:
The ExportRangeAsImage () method, which exports the data area of an Excel file to image files, is called in a background worker, which is implemented in the same class (ViewModel). If the update of a file runs while it is displayed at the same time, I get the following error:
// ExportRangeAsImage() {
...
System.Windows.Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Normal, new System.Action(() =>
{
Bitmap image = new Bitmap(System.Windows.Forms.Clipboard.GetImage());
if (!file.Contains("XYZ"))
{
//The program stops here
image.Save(ImagePathM1 + Path.GetFileNameWithoutExtension(file) + ".svg"); Marshal.ReleaseComObject(ExcelApp);
}
}));
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll Additional information: A generic error occurred in GDI+.**
I guess it is because the file that is being displayed and file has the same name and the program can not change or overwrite a file that is being used!
Can you help me solve this problem ???