|
-
Jun 11th, 2007, 01:47 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] Closing threads when program closes
Hi Everyone,
I have an application that has threads continually running in the background monitoring different settings. When the end users x's out of my program, the threads remain as a process in windows even though the GUI is closed.
How do I terminate the threads when the GUI is x'd out, or how do I put logic into the threads to end if the GUI is closed?
Thank you all in advance.
-
Jun 11th, 2007, 02:04 PM
#2
Hyperactive Member
Re: [2005] Closing threads when program closes
like this, i think thats the right name for that event...maybe before close or something, im sure youl get it.....
Code:
private sub on_close(byval sender as object... blabla) handles me.onclosing
yourthread.stop
end sub
-
Jun 11th, 2007, 03:26 PM
#3
Re: [2005] Closing threads when program closes
vb Code:
Private Sub form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
I use the form closing event to deal with things like this. If your using background workers to run the other threads then couldnt you use backgroundworkername.dispose() ?
-
Jun 11th, 2007, 11:26 PM
#4
Re: [2005] Closing threads when program closes
Set the IsBackground property of each Thread object to True. That is only safe to do if the threads are guaranteed not to leave anything in an invalid state if they are terminated implicitly.
-
Jun 12th, 2007, 05:53 AM
#5
Thread Starter
Addicted Member
Re: [2005] Closing threads when program closes
On the _FormClosed event, how would I stop a thread that is started like the below code?
Code:
Dim t As New Thread(AddressOf runContactThread)
t.Start()
JMC,
Set the IsBackground property of each Thread object to True.
How would I do that with the above code?
-
Jun 12th, 2007, 11:09 AM
#6
Thread Starter
Addicted Member
Re: [2005] Closing threads when program closes
Does anyone know how to kill this thread on the _FormClosed event?
Code:
Dim t As New Thread(AddressOf runContactThread)
t.Start()
-
Jun 12th, 2007, 11:16 AM
#7
Re: [2005] Closing threads when program closes
 Originally Posted by Giraffe Frenzy
Does anyone know how to kill this thread on the _FormClosed event?
Code:
Dim t As New Thread(AddressOf runContactThread)
t.Start()
Just use the IsBackground method like jmcilhinney mentioned.
Code:
Dim t As New Thread(AddressOf runContactThread)
t.IsBackGround = True
t.Start()
-
Jun 12th, 2007, 11:18 AM
#8
Thread Starter
Addicted Member
Re: [2005] Closing threads when program closes
I figured it out.
On the _FormClosed event, type
-
Jun 12th, 2007, 11:23 AM
#9
Re: [2005] Closing threads when program closes
 Originally Posted by Giraffe Frenzy
I figured it out.
On the _FormClosed event, type
You shouldnt be using End. End is an old vb6 way of terminating the application. Why would you want to do that in the formclosed event?
Did you even try the IsBackground property?
-
Jun 12th, 2007, 11:54 AM
#10
Thread Starter
Addicted Member
Re: [RESOLVED] [2005] Closing threads when program closes
jmc and Atheist,
thank you. I tried IsBackground as you suggested. This also worked. Based on what you said Atheist, I will use the IsBackground. Thank you all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|