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. 3 1884
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.
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.
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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()
{
}
|
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...
|
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...
|
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...
|
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() ...
|
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,...
|
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...
|
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.
|
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...
|
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...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |