Export Image Tiff does not work in multithreading

Posted by: developers on 29 November 2020, 7:41 pm EST

  • Posted 29 November 2020, 7:41 pm EST

    I implemented a paralell foreach and I always get the following error message:

    The size of the bitmap is too large that there is not enough memory in system can be allocated to the bitmap.

    I generate 200 and more Reports and will export in tiff files

    and would like to be as efficient as possible with the Tiff export.

    Here is the complete error message:

    Cannot create the tiff document. Name: ActiveReports Document;System.Exception*Void CommonExport(GrapeCity.ActiveReports.Document.SectionDocument, System.String, System.IO.Stream)The size of the bitmap is too large that there is not enough memory in system can be allocated to the bitmap. bei GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport.CommonExport(SectionDocument document, String pageRange, Stream outputStream)

    I use the version 14.1.20320

    The problem is the parallel.Foreach →

    Developer envirorment:

    I must limited the MaxDegreeOfParallelism to 3, because it’s higher then 3 then it throws exception in marked code line!

    Customer envirorment:

    MaxDegreeOfParallelism = 3 does not fix the problem. The customer continues to receive the same error message.

    
    public static void ArchiveTiffFiles(IList<PrintDocuments> allReports, string tiffFilePath) // in allReports are 200 Reports --> one generated TiffFile is 33.1 MB in size
    {
    	var resultReportlst = allReports.Where(re => re.IndexValue != null).GroupBy(report => report.OrderCounter).OrderBy(rp => rp.Key);
    	
    	Parallel.ForEach(resultReportlst, new ParallelOptions { MaxDegreeOfParallelism = 4 },  report =>
    	{
    		foreach (var exportDocumentPage in report.Document.Document.Pages)
            {
    			var tmpSectiondocument = new SectionDocument();
                tmpSectiondocument.Pages.Add(exportDocumentPage);
                if (report.Document.Document.Pages.Count > 1)
                {
    				fileCount = documentPageCounter++;
                }
                else
                {
    				fileCount += documentPageCounter++;
                }
                string tifffilenumber = fileCount.ToString("D3");
    			
    			GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport tiffSetting = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport();
    			tiffSetting.CompressionScheme = CompressionScheme.None;
    			tiffSetting.Dither = true;
    			tiffSetting.DpiX = 300;
    			tiffSetting.DpiY = 300;
    			tiffSetting.Pagination = true;
            
    			tiffSetting.Export(tmpSectiondocument, Path.Combine(tiffFilePath, tifffilenumber) + ".tif"); // Here throws the exception with the message: The size of the bitmap is too large that there is not enough memory in system can be used to draw the report on the bitmap.
    			tiffSetting.Dispose();	
    		}
    		
    	});
    
    }
    
    

    How can I fix this problem? I dispose of the export settings…

    Regards,

    Ramona

  • Posted 1 December 2020, 11:34 pm EST

    Hello,

    Could you please share the exact environment detail (RAM, OS, Harddisk) of both machine(developer machine and customer machine).

    Also, please share the are you running you application at 32 or 64 bit target environment.

    If possible, could you please share the stripped down application so that I can reproduce the issue at my end.

    Thanks,

    Mohit

  • Posted 4 December 2020, 2:53 am EST

    Hello Mohit,

    Customer:

    Windows Server 2012 R2

    C: has 139 GB, currently free 14.6 GB.

    RAM is 16.0 GB (usually distributed over 3-4 users)

    Developer:

    Windows 10 Pro

    C: has 500GB, currently free 280GB

    RAM is 16GB (1 user)

    I’ll get in touch as soon as I have a little solution to hand over to you.

  • Posted 6 December 2020, 3:24 pm EST

    Hello,

    It seems related to memory issue as customer have only 16 GB ram which is used by 3-4 user as compared to developer machine. In my understanding, customer does not enough memory available to run the application at their end.

    Thanks,

    Mohit

  • Posted 7 December 2020, 7:37 am EST

    Hello Mohit,

    but this answer fix not the main problem.

    MaxDegreeOfParallelism = 3 → crashed by customer environment

    but MaxDegreeOfParallelism = 4 → crashed by developer environment.

    The main problem be located by the tiffexport setting object. It is not cleaned up in time.

    As soon as I have my solution ready I will send you this.

  • Posted 7 December 2020, 3:50 pm EST

    Hello,

    In my understanding the main issue related to memory consumption. However, I am waiting for the sample so that I can check at my end.

    Thanks,

    Mohit

  • Posted 8 December 2020, 9:21 am EST

    Hello Mohit,

    I have a little difficulty creating my solition. I don’t want to give out customer-relevant codes and data. Therefore I try to create an RPX from a merged report (added with Document.Pages.AddRange method). Unfortunately the RPX file is empty. How can I save an RPX from a SectionDocument? (I try report.Document.SaveLayout method)

  • Posted 8 December 2020, 2:01 pm EST

    Hello,

    You can share the RDF file with by using the SectionDocument.Save(“Test.rdf”). Also, have you observed the memory consumption when you run your application in Task Manager or any memory profiler tool?

    Thanks,

    Mohit

  • Posted 10 December 2020, 3:13 am EST

    Hello Mohit,

    Can I recreate from a rdf file the SectionDocument and all there merged SectionReports?

    I need this to recreate the bug.

    Parallel.ForEach(resultReportlst, new ParallelOptions { MaxDegreeOfParallelism = 4 }, report =>

    {

    foreach (var exportDocumentPage in report.Document.Document.Pages)

    {

    var tmpSectiondocument = new SectionDocument();

    tmpSectiondocument.Pages.Add(exportDocumentPage);

    if (report.Document.Document.Pages.Count > 1)

    {

    fileCount = documentPageCounter++;

    }

    else

    {

    fileCount += documentPageCounter++;

    }

    string tifffilenumber = fileCount.ToString(“D3”);

    		GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport tiffSetting = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport();
    		tiffSetting.CompressionScheme = CompressionScheme.None;
    		tiffSetting.Dither = true;
    		tiffSetting.DpiX = 300;
    		tiffSetting.DpiY = 300;
    		tiffSetting.Pagination = true;
        
    		tiffSetting.Export(tmpSectiondocument, Path.Combine(tiffFilePath, tifffilenumber) + ".tif"); // Here throws the exception with the message: The size of the bitmap is too large that there is not enough memory in system can be used to draw the report on the bitmap.
    		tiffSetting.Dispose();	
    	}
    	
    });
    
  • Posted 10 December 2020, 3:18 pm EST

    Hello,

    Can I recreate from a rdf file the SectionDocument and all there merged SectionReports?

    Yes, you can simple load the rdf file in the SectionDocument like follow:

    sectionDocumnet.Load(“Test.rdf”);

    Please refer to the following link:

    https://www.grapecity.com/activereportsnet/docs/v14/online/save-and-load-report-files-rdf.html

    Thanks,

    Mohit

  • Posted 10 December 2020, 8:30 pm EST

    Good mornig Mohit,

    I greate a Solution here is the link:

    https://drive.swiss-egov.cloud/t/lz9hwyg3

    I found out why it throws an exception.

    If the solution runs on 64bit, it throws no exception.

    If it runs on 32bit → it throws an exception exactly at the marked point.

    Regards,

    Ramona

  • Posted 14 December 2020, 3:09 am EST

    Hello,

    I am able to reproduce the issue at my end on 32 bit environment. However, in 32 bit environment resource allocation is less than as comparative to 64 bit. Also, In 32 bit, it uses max 2 GB of RAM of your system but in 64 bit it can use maximum available RAM. So, I suggest you to use the application in 64 environment only.

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels