P B

P B

  • NA
  • 1
  • 2.9k

Crystal Reports not unloading properly from memory

Jun 29 2012 9:59 AM
Hi. Here's the problem i'm running into (VS 2010, .net 3.5, Crystal Reports 2008):

I've got a form, frmReports, that has a CrystalReportsViewer control on it. This form is instanced by a button_click from another form. Upon loading frmReports loads a report document into the viewer, which takes at least 3 minutes to display (the efficiency is not in question here; the database is very large and the report uses a stored procedure).

For this reason i have created a background worker that checks for a keyboard combination. This is supposed to prompt the user that he has chosen to interrupt the loading, dispose of everything and close the form (frmReports).

Everything works very well, the key event is sent, the user is notified(the background worker is disposed properly), but after pressing OK to close the messagebox, the main thread remains locked (i cannot do anything on any form).

I've used ANTS memory profiler and all the CrystalDecisions assemblies are still loaded into the memory, and the report document is actually still working in the background.

I've tried crViewer.ReportSource.Close(), setting it to = nothing, ReportSource.Database.Dispose(), changing the AppDomain and unloading the assemblies, forcing GC.Collect(), and many combinations, and NOTHING WORKED - the report still doesn't release its resources and keeps on trying to load in the background (i think in some unmanaged thread as pausing my program doesn't interrupt anything).

Is there any way to properly unload everything Crystal Reports loaded? or to forcibly close the connection to the database (without doing anything to the sql server)??