473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1885
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
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() { }
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
6
by: RickDee | last post by:
Understand that when I start a thread, a number will be generated and is able to get from GetHashCode method. But I would like to use this number when I want to kill certain thread, anybody know...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
6
by: Joe | last post by:
I've been getting this message at all different times since a few days ago. I understand the message but not why I get it. I don't have any other threads. This happens when closing dialog boxes,...
9
by: MarGera332 | last post by:
Hey Everyone I have a problem, that just wont seem to go away. Here is the setup, i has one outer div with two divs inside, one large on the left and a small div on the right, i need the div on...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: qutspan | last post by:
When I create taskbox on the form the line beside the box wont show up. it show up untill I have MouseEnter event occur. Also when I have 2 taskbox on the form it does draw the line around the...
14
by: Meganutter | last post by:
Hello, I have searched far and wide, and i found millions of post telling "BAD" or "you should have regular checks" but that wont work for me. the problem is, i have a program that is all about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.