Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi! Everybody. How about you. I want to ask What is Difference Between Timer and Thread in C# window form . I already read some answer from the internet. But i don't understand very will. Someone can explain me with example.

Thanks you all of my brothers for your attention
Posted
Comments
Herman<T>.Instance 14-Aug-14 5:22am    
MSDN? Ever heard of it?

A timer is a means of ensuring that actions happen in your application at a specific time, or at regular intervals, by signalling a event that your application responds to and performs some action. It should not be assumed that a Timer will result in the event occurring at any specific time or interval - the event may be signaled at the specific time, but that doesn't mean that your application will be able to respond to it at that instant.
It's a bit like having an alarm clock that is set to go off at 07:00 - it raises an "alarm" event which you respond to by either getting up, or pressing the "snooze" button.

A thread is the "basic unit" of processing: each thread contains it's own memory (in the form of a stack, the heap is common to all threads within an application) and an application will often have more than one thread - it will always have a minimum of one. Multiple threads can operate at the same time (if there are sufficient spare cores available in your processor) or they can appear to operate at the same time because the operating system can preemptively switch between them to share out the work.
Very often, multiple threads are used to move tasks which take a long time away from threads which interact directly with the user, allowing them to remain responsive. Or, the same task can be performed on a number of threads at the same time, all using different data - so instead of a loop processing each item in sequence you can do a number of them at the same time.
It's a bit like having a class full of students: you can get them all working on the same problem (one thread) or you can break the task into smaller chunks and pass it out to individual students (multiple threads).
 
Share this answer
 
Comments
naylynn 14-Aug-14 7:42am    
Thanks you brother. you are good explain me and give good example. Now i understand more than.
OriginalGriff 14-Aug-14 8:22am    
You're welcome!
naylynn 14-Aug-14 10:20am    
:)
A timer is merely a clock process that allows your program to receive interrupts at fixed intervals, so you can perform some action; see http://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx[^].

A thread is a process that runs independently within a program's address space, and can interact (or not) with other threads. It allows you to run multiple processes in parallel, and is especially useful to stop long runing processes from making your program look as though it is not doing anything. See http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx[^].
 
Share this answer
 
Comments
CPallini 14-Aug-14 5:28am    
5.
naylynn 14-Aug-14 7:35am    
Thanks brother. I more understand than before. Your answer is helpful for me.
Sergey Alexandrovich Kryukov 14-Aug-14 7:15am    
A timer is not a "clock process", and is not a "process". It's a mechanism based on hardware interrupt, pretty hard to explain. And a thread is not a process. Also hard to explain, would need a big article to explain, if not a book. I would prefer not answering such a bad incorrect question about "difference".
—SA
Richard MacCutchan 14-Aug-14 8:21am    
Yes they are.
Sergey Alexandrovich Kryukov 15-Aug-14 0:38am    
Well, maybe only in some figurative sense of this word. The "difference" between process and thread is a commonplace, often discussed. How a literate engineer, anyone, will look at your sayings..?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900