How to close a thread?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a procedure that creates a file, then generates a log report via
Crystal. If the user closes the form after the file is created and before the
log appears, the form closes, but (it appears that) a thread creating the
Crystal report continues to run. How do I get hold of the thread and close
it, or alternatley, look to see if it's running so I can delay close of the
form?
 
eye5600,
We would probably need to see a "Short But Complete" code snippet to see
how this is being done. If your code creates a thread in order to do the
Crystal thing,
you could call the Join method on it, provided it is set as a background
thread.

Peter
 
We would probably need to see a "Short But Complete" code snippet to see
how this is being done.

oRpt.SetDataSource(dsRpt) ;
crView.ReportSource = oRpt ;

I'm just displaying the report, but the it takes long enough to appear (~5
sec) that it's easy to forget it's comming, and close the form.
 
I usually show a hourglass kind of thing, in my case my own form with a
clock and a moving icon, to give prompt to the users that something is
happening. Additionally I catch distroy and prompt users if they really want
to cancel action. Maybe you want to find a better way than this but usually
it works for my clients.
 
Yes,
There is no separate thread to deal with here. You need to find out if there
is a return value from this method call which would let you not allow the
user to close the form until it has returned, or a timeout has occured. In
the meantime, you could have some visual indicator on the form that shows the
user it is working. An hourglass cursor as suggested is a good step.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
I need a tad more detail. If the user closes the form using the close box in
the upper right, is there any way to intercept it besides the close event? If
I put code in the close event to delay until the processing is complete, how
do I make the program delay until my flag changes?
 
Creating the closing event for the form and setting e.Cancel to the
appropriate value as described in the doc for the CancelEventArgs Class seems
to obviate the problem. I don't completely understand how this works (e.g. it
does not seem to return control to the user the way I might expect), but it
solves the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top