Hello all
Within my reports form i have used delegates to allow a crystall
reports to generate without holding up the user.
The user selects a report from tree view, enters the appropriate data
and then hits the "Display" button. At this point the delegate is
created and fired via BeginInvoke.
The code run within the delegate call includes calls to the database
to retrieve data, insertion of data into a dataset, as well as some
business logic. Eventually the ReportSource is set to the crystall
report and displayed in the CrystalReportVi ewer.
I currently know that i have some no nos within my code as i am
accessing Control objects outside of the main UI thread.
(eg. Setting reportViewer.Re portSource = myReport;)
And i will get onto changing this soon.
My problem is:
When the user closes the form the new thread that has been generated
using
myReportDelegat e.BeginInvoke() is still running. I need this code
path to terminate execution. Because when i load the form again the
and go to run another report the DB will still have an open connection
from the thread before.
I have searched google & microsoft and basically i found the example:
HOWTO: Stop Multiple Threads
http://msdn.microsoft.com/library/de...tml/stopmt.asp
This sets a property in the closing event and simply checks this value
in the thread, returning out of the method once the property has been
set to true.
This example is no good in my case as there is no consistent looping
in the thread code so this property cannot be checked regulary
Unless i put
if (HasClosed)
return;
in every 2nd line of code which is very very messy.
Does anyone have an idea of how i can terminate the thread generated
off the delegate when the form closes, or am i completely on the wrong
path with the whole code execution via delegates??
Thanks in advance..
Ginno...