Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

How to close a thread?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eye5600 - 20 Dec 2005 20:51 GMT
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?
Peter Bromberg [C# MVP] - 20 Dec 2005 21:00 GMT
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
Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> 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 - 20 Dec 2005 21:48 GMT
> 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.
Pohihihi - 20 Dec 2005 22:32 GMT
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.

>> We would probably need to see  a "Short But Complete" code snippet to see
>> how this is being done.
[quoted text clipped - 4 lines]
> 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.
Peter Bromberg [C# MVP] - 20 Dec 2005 23:43 GMT
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

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> > We would probably need to see  a "Short But Complete" code snippet to see
> > how this is being done.
[quoted text clipped - 4 lines]
> 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.
eye5600 - 21 Dec 2005 14:11 GMT
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
[quoted text clipped - 3 lines]
> user it is working. An hourglass cursor as suggested is a good step.
> Peter
eye5600 - 21 Dec 2005 14:40 GMT
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.
pbromberg@gmail.com - 23 Dec 2005 15:27 GMT
Take a look at the Form class's events. "Closing" is probably what you
want to use.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemwindowsformsformclasstopic.asp


Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.