Pergunta

Our software needs to produce variable-sized reports, which can easily move past 100 pages. Several of these pages contain large images/Bitmaps.

Is there a reliable way to prevent the overall report from consuming all available memory? Once we have enough pages being generated, the app almost never finishes creating the report without running out of memory. Most of the memory is consumed by Bitmaps that we cannot release. (Attempting to dispose of them before the report is complete causes the report generation to fail.)

Foi útil?

Solução

John

Have you tried using the cache to disk with ActiveReports?

http://helpcentral.componentone.com/nethelp/AR7Help/OnlineEn/CacheToDiskAndResourceStorage.html More details here: http://helpcentral.componentone.com/nethelp/AR7Help/OnlineEn/GrapeCity.ActiveReports.Document.v7~GrapeCity.ActiveReports.Document.SectionDocument~CacheToDisk.html

Set this up prior to running the report. For example: report.Document.CacheToDisk = true; report.Run();

Outras dicas

I think you could try spliting ur report into smaller chunks ,run them and then merge all the reports into one once all pages have been generated.

One more suggestion in addition to setting CacheToDisk property of ActiverReports to True would be to make use of Image.FromStream instead of Image.FromFile to access the images.

Image.FromFile leaves file handles open, and hence it may result in the Memory Exception.

using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
   using (Image original = Image.FromStream(fs))
   {
      ...
   }
}

Using an explicit Dispose(), a using() statement or setting the value to null on the bitmap doesn't generally solve the issue with Image.FromFile.

So if you App runs for a time and opens a lot of files consider using Image.FromStream() instead.

Regards, Mohita

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top