471,337 Members | 978 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

How to close a thread?

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?
Dec 20 '05 #1
7 1593
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"eye5600" wrote:
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?

Dec 20 '05 #2
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.
Dec 20 '05 #3
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.
"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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.

Dec 20 '05 #4
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


"eye5600" wrote:
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.

Dec 20 '05 #5
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?
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


Dec 21 '05 #6
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.
Dec 21 '05 #7
Take a look at the Form class's events. "Closing" is probably what you
want to use.

http://msdn.microsoft.com/library/de...classtopic.asp

Peter

Dec 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by drs | last post: by
1 post views Thread by Ebrahim | last post: by
3 posts views Thread by nick_nw | last post: by
reply views Thread by meLlamanJefe | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.