473,408 Members | 1,870 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,408 software developers and data experts.

Timer dispose does not end thread

Hello everyone
I have a beginner's questions about the System.Threading.Timer class
behavior. I have been observing the thread count with Windows Task
Manger and noticed that timers, after being disposed, do not seem to
end their thread after the timers stop working).

For instance, when making a simple timer with the following code:

public System.Threading.Timer timerTest;
public System.Threading.TimerCallback tCallBack;

....

tCallBack = new System.Threading.TimerCallback(Callback);
timerTest = new System.Threading.Timer(tCallBack,null, 3000, 3000);

....

public void Callback(object state)
{ iCount++;
label1.Text = iCount.ToString();
if (iCount == 10)
timerTest.Dispose();
}

The program's thread count would jump from 3, to 6 (sometimes even
7?), but when the iCount would reach 10, and the dispose for the timer
would be called, the thread count would not drop. So based on that I
am presuming, the threads for the timer do not actually stop, but are
rather suspended?

On the other hand, when I create a custom thread and stop it, the
thread count in Windows Task Manager does decrease appropriately. So
why are the threads for the timer staying "alive"? How can I clean up
the resources? (I have tried invoking garbage collector, but the
threads do not get stopped, based on the Task Manager).

Thank you for any advice/answers in advance,
Amadej.

Nov 16 '05 #1
2 13145

"Amadej" <Am************@leoss.si> wrote in message
news:tr********************************@4ax.com...
Hello everyone
I have a beginner's questions about the System.Threading.Timer class
behavior. I have been observing the thread count with Windows Task
Manger and noticed that timers, after being disposed, do not seem to
end their thread after the timers stop working).
[snip] On the other hand, when I create a custom thread and stop it, the
thread count in Windows Task Manager does decrease appropriately. So
why are the threads for the timer staying "alive"? How can I clean up
the resources? (I have tried invoking garbage collector, but the
threads do not get stopped, based on the Task Manager).

Thank you for any advice/answers in advance,
Amadej.


System.Threading.Timer uses a thread from the thread pool (see
System.Threading.ThreadPool class). These threads are managed by the system
and you don't need to worry about terminating them. Everything should be
fine resource-wise as long as you call Dispose on the timer objects.

Regards,
Sami
Nov 16 '05 #2
On Mon, 19 Jul 2004 13:50:21 +0300, "Sami Vaaraniemi"
<sa**********@pleasejippii.fi> wrote:
System.Threading.Timer uses a thread from the thread pool (see
System.Threading.ThreadPool class). These threads are managed by the system
and you don't need to worry about terminating them. Everything should be
fine resource-wise as long as you call Dispose on the timer objects.

Regards,
Sami


Oh, okay I seem to have missed that part. Thank you for a quick
response Sami.

Regards,
Amadej.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
2
by: KSC | last post by:
Hello, I have used a thread timer as in the documentation on MSDN in my VB.NET application. Using System.Threading.Interlocked.Increment I increment the counter to a certain point, perform an...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
1
by: ChainsawDude | last post by:
I note that when I set a culture in the globalization section of the web.config this is picked up and used for methods such as ToString() for dates etc. However, it is not picked up for timers...
8
by: RobcPettit | last post by:
Hi Im using System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Elapsed += new ElapsedEventHandler(onTimer); myTimer.Interval = 1000; myTimer.Start(); and getting error onTimer does...
2
by: Dipankar | last post by:
In an Windows application I have created a Timer to monitor some WorkerThread's state. Once the worker thread stops the timer should also dispose after displaying the message that Worker Thread is...
2
by: Amit Dedhia | last post by:
Hi I am developing a scientific application which has moderate level image processing involved. In my application, there is a main application form which invokes another form. When this form...
1
by: =?Utf-8?B?QnNtZW5nZW4=?= | last post by:
I create the timer like this: StreamingTimer = new System.Timers.Timer(); StreamingTimer.Elapsed += new System.Timers.ElapsedEventHandler(StreamingProc); StreamingTimer.Interval = 1000;...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.