468,272 Members | 1,999 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Thread Wont Go Away!

Ok, this is probably a simple and stupid question, but its giving me hell.

Lets say that this is my app

public class myapp : System.Windows.Forms.Form
{
public myapp()
{
}

private void btnGo_Click(blah, blah)
{
ThreadStuff ts = new ThreadStuff();
}
}

public class ThreadStuff
{
Thread tt;
public ThreadStuff()
{
tt = new Thread(new ThreadStart(this.GoDoSomething));
tt.Start();
}
private void GoDoSomething()
{
while(true)
{
Thread.Sleep(new timespan(0,0,10);
}
}
}

I know the app does nothing, but stay with me:)

When I close the app the process is still running in task manager. What do
I need to do to clean up the thread and abort it? Shouldnt the instance of
ThreadStuff get disposed of and does that not kill all the objects including
the threat tt?

Obviously, Im doing something wrong. Let me know what the best way to kill
a thread that is running whenever the application is closed.

Thanks for the help.
Nov 22 '05 #1
3 1730
Set the 'IsBackground' property of your thread to 'true' before you Start()
it.
"Matt" <ev******@email.com> wrote in message
news:uN****************@TK2MSFTNGP12.phx.gbl...
Ok, this is probably a simple and stupid question, but its giving me hell.

Lets say that this is my app

public class myapp : System.Windows.Forms.Form
{
public myapp()
{
}

private void btnGo_Click(blah, blah)
{
ThreadStuff ts = new ThreadStuff();
}
}

public class ThreadStuff
{
Thread tt;
public ThreadStuff()
{
tt = new Thread(new ThreadStart(this.GoDoSomething));
tt.Start();
}
private void GoDoSomething()
{
while(true)
{
Thread.Sleep(new timespan(0,0,10);
}
}
}

I know the app does nothing, but stay with me:)

When I close the app the process is still running in task manager. What do I need to do to clean up the thread and abort it? Shouldnt the instance of ThreadStuff get disposed of and does that not kill all the objects including the threat tt?

Obviously, Im doing something wrong. Let me know what the best way to kill a thread that is running whenever the application is closed.

Thanks for the help.

Nov 22 '05 #2
Set the 'IsBackground' property of your thread to 'true' before you Start()
it.
"Matt" <ev******@email.com> wrote in message
news:uN****************@TK2MSFTNGP12.phx.gbl...
Ok, this is probably a simple and stupid question, but its giving me hell.

Lets say that this is my app

public class myapp : System.Windows.Forms.Form
{
public myapp()
{
}

private void btnGo_Click(blah, blah)
{
ThreadStuff ts = new ThreadStuff();
}
}

public class ThreadStuff
{
Thread tt;
public ThreadStuff()
{
tt = new Thread(new ThreadStart(this.GoDoSomething));
tt.Start();
}
private void GoDoSomething()
{
while(true)
{
Thread.Sleep(new timespan(0,0,10);
}
}
}

I know the app does nothing, but stay with me:)

When I close the app the process is still running in task manager. What do I need to do to clean up the thread and abort it? Shouldnt the instance of ThreadStuff get disposed of and does that not kill all the objects including the threat tt?

Obviously, Im doing something wrong. Let me know what the best way to kill a thread that is running whenever the application is closed.

Thanks for the help.

Nov 22 '05 #3
Design your thread handling classes to do a clean shutdown. I posted an
example in the past. Do google groups search with this pattern to find
it. "Shutdown pattern lambertl". This was done for Java but it is nearly
the same as C#.

Hope this helps
Leon Lambert
Shaniqua VonTheimenwhinselBergensteinSki wrote:
Set the 'IsBackground' property of your thread to 'true' before you Start()
it.
"Matt" <ev******@email.com> wrote in message
news:uN****************@TK2MSFTNGP12.phx.gbl...
Ok, this is probably a simple and stupid question, but its giving me hell.

Lets say that this is my app

public class myapp : System.Windows.Forms.Form
{
public myapp()
{
}

private void btnGo_Click(blah, blah)
{
ThreadStuff ts = new ThreadStuff();
}
}

public class ThreadStuff
{
Thread tt;
public ThreadStuff()
{
tt = new Thread(new ThreadStart(this.GoDoSomething));
tt.Start();
}
private void GoDoSomething()
{
while(true)
{
Thread.Sleep(new timespan(0,0,10);
}
}
}

I know the app does nothing, but stay with me:)

When I close the app the process is still running in task manager. What


do
I need to do to clean up the thread and abort it? Shouldnt the instance


of
ThreadStuff get disposed of and does that not kill all the objects


including
the threat tt?

Obviously, Im doing something wrong. Let me know what the best way to


kill
a thread that is running whenever the application is closed.

Thanks for the help.



Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matt | last post: by
31 posts views Thread by AlexeiOst | last post: by
6 posts views Thread by RickDee | last post: by
7 posts views Thread by Ivan | last post: by
51 posts views Thread by Hans | last post: by
reply views Thread by qutspan | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.