Click here to Skip to main content
15,913,467 members
Home / Discussions / C#
   

C#

 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:28
sitebuilderLuc Pattyn3-Dec-09 3:28 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:36
Jacob Dixon3-Dec-09 3:36 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:58
sitebuilderLuc Pattyn3-Dec-09 3:58 
GeneralRe: Killing threads on form closing... Pin
ely_bob3-Dec-09 8:03
professionalely_bob3-Dec-09 8:03 
AnswerRe: Killing threads on form closing... Pin
Nicholas Butler3-Dec-09 3:17
sitebuilderNicholas Butler3-Dec-09 3:17 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:21
Jacob Dixon3-Dec-09 3:21 
GeneralRe: Killing threads on form closing... Pin
Nicholas Butler3-Dec-09 3:36
sitebuilderNicholas Butler3-Dec-09 3:36 
AnswerRe: Killing threads on form closing... Pin
Ian Shlasko3-Dec-09 3:20
Ian Shlasko3-Dec-09 3:20 
I would do things a bit differently, in three ways...

1) Use a BackgroundWorker instead of a Thread (System.ComponentModel namespace). This can be set to raise ProgressChanged events on the GUI thread, so you don't have to deal with the invokes. It also has an IsBusy property that you can use when deciding whether to allow the user to close the form.

2a) Declare the worker at the form/window level, so you can kill it when the form is closing (Or not allow the close if it's running)

OR

2b) Create an IsBusy property on the form. Set it to true just before starting the thread/worker, and set it back to false when the worker completes (BackgroundWorkers have a RunWorkerCompleted event you can catch)

3) Instead of having the thread access form-level variables (Particularly if you use (2b) above, create a quick struct with the two strings and bool in it, and pass that as an argument to the thread/worker. It's preferable to have background threads be as self-contained as possible.

Proud to have finally moved to the A-Ark. Which one are you in?
Author of Guardians of Xen (Sci-Fi/Fantasy novel)

GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:32
Jacob Dixon3-Dec-09 3:32 
GeneralRe: Killing threads on form closing... Pin
Ian Shlasko3-Dec-09 4:04
Ian Shlasko3-Dec-09 4:04 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:43
Jacob Dixon3-Dec-09 3:43 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 5:38
sitebuilderLuc Pattyn3-Dec-09 5:38 
AnswerRe: Killing threads on form closing... Pin
PIEBALDconsult3-Dec-09 4:49
mvePIEBALDconsult3-Dec-09 4:49 
QuestionRedundant function? Pin
Spoon Of Doom3-Dec-09 2:51
Spoon Of Doom3-Dec-09 2:51 
AnswerRe: Redundant function? Pin
David Skelly3-Dec-09 3:05
David Skelly3-Dec-09 3:05 
AnswerRe: Redundant function? Pin
J4amieC3-Dec-09 3:10
J4amieC3-Dec-09 3:10 
AnswerRe: Redundant function? Pin
Spoon Of Doom3-Dec-09 3:25
Spoon Of Doom3-Dec-09 3:25 
QuestionMaking the code in a DLL invisible Pin
Dewald2-Dec-09 22:18
Dewald2-Dec-09 22:18 
AnswerRe: Making the code in a DLL invisible Pin
Calla2-Dec-09 22:33
Calla2-Dec-09 22:33 
GeneralRe: Making the code in a DLL invisible Pin
Dewald2-Dec-09 22:55
Dewald2-Dec-09 22:55 
AnswerRe: Making the code in a DLL invisible Pin
harold aptroot2-Dec-09 22:38
harold aptroot2-Dec-09 22:38 
GeneralRe: Making the code in a DLL invisible Pin
Dewald2-Dec-09 23:05
Dewald2-Dec-09 23:05 
AnswerRe: Making the code in a DLL invisible Pin
Saksida Bojan2-Dec-09 22:40
Saksida Bojan2-Dec-09 22:40 
GeneralRe: Making the code in a DLL invisible Pin
Dewald2-Dec-09 22:53
Dewald2-Dec-09 22:53 
GeneralRe: Making the code in a DLL invisible Pin
Calla2-Dec-09 23:46
Calla2-Dec-09 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.