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

Threads v Timers

750 Expert 512MB
Use a System.Timers.Timer. You can call a function on elapsed event.
In the service on start method, enable the timer.

Timer(MSDN):
"The Timer component is a server-based timer, which allows you to specify a recurring interval at which the Elapsed event is raised in your application. You can then handle this event to provide regular processing. For example, suppose you have a critical server that must be kept running 24 hours a day, 7 days a week. You could create a service that uses a Timer to periodically check the server and ensure that the system is up and running. If the system is not responding, the service could attempt to restart the server or notify an administrator."
Jan 28 '10 #1
9 7607
sanjib65
102 100+
I'd like to extend this interesting thread a little further. What is the basic difference between Timer and Thread. Both are used to pause the application for a certain time, I guess?
Jan 28 '10 #2
PRR
750 Expert 512MB
Thread and Timers are different.Timers are used to execute certain tasks after a defined interval. Threading is execution of tasks simultaneously. Some timers internally use threads( System.Timers.Timer for eg).
Thread: Programs that use more than one thread properly/ correctly are better responsive and more use friendly. Having multiple threads in a program, enables the program to do more work simultaneously. Multiple threads can exists within same process sharing memory, files and other resources.

Timers: Timer objects in .Net Framework allow you to execute certain function/code regularly. There are three timers in Framework
1. System.Timers.Timer
2. System.Windows.Forms.Timer
3. System.Threading.Timer

Each application has a pool of threads, normally around 20-50 called threadpool. Threadpool are background threads. System.Timers.Timer in its elapsed event spawns new threads( from threadpool).
Jan 28 '10 #3
sanjib65
102 100+
Many thanks PRR, nicely explained but I wanted to know another thing. Suppose, in an data application using AJAX when we use System.Thresding.Thread.Sleep(3000) and pause the UpdateProgress for 3 seconds, does it not do something(suppose updating data in a ListView) after a certain interval? I mean, it seems doing something like Timer though both are different in nature, no doubt.
Best of Luck.
Jan 28 '10 #4
tlhintoq
3,525 Expert 2GB
Sanjib65: In the future please do not hijack someone else's thread/question for your own needs. You are always welcome to start a new thread and even reference an existing thread.

"I was looking at this question xxxxxxxx when it got me thinking about zzzzzzz"

I have split your question and PRR's answers to their own thread.
Jan 28 '10 #5
tlhintoq
3,525 Expert 2GB
System.Thresding.Thread.Sleep(3000) and pause the UpdateProgress for 3 seconds, does it not do something(suppose updating data in a ListView) after a certain interval?
When the thread is asleep - NOTHING happens on that thread. Loops are not run, events are not reacted to, queue's are not processed. NOTHING.

My personal opinion and coding style:
Thread.Sleep is rarely what someone really wants, but it often what people will use. In your example of wanting to pause the update of a progress bar. If the progress bar is on it's own thread, and nothing else happens then it might be ok. But if you sleep the progressbar, and it is supposed to react to an event on another thread so it can update, then it won't hear the event it is supposed to react to. I personally prefer a loop that will cause it to continue to be responsive, yet not proceed in code.

Expand|Select|Wrap|Line Numbers
  1. DateTime dtBailout = DateTime.Now.AddSeconds(3);
  2. while (DateTime.Now < dtBailout)
  3. {
  4.     Application.DoEvents();
  5. }
  6. // Continue doing something
Jan 28 '10 #6
sanjib65
102 100+
tlhintoc, as a moderator you can always overpower me and delete my thread and even you can write this kind of line:
Sanjib65: In the future please do not hijack someone else's thread/question for your own needs.
But I have a question, is your forum not open for other good free tutorials or links? If someone like me wants to share his nice experience of learning elesewhere and give a reference to that link, it will be deleted immidiately?
Then what is basic of sharing knowledge in a FORUM?
If my tone seems to be harsh please forgive me. If this is the rule here, I am bound to obey and in future I won't refer any free link where one can get his helps.
Best of Luck
Jan 29 '10 #7
tlhintoq
3,525 Expert 2GB
The forum is available to all, provided they follow the posting guidelines, which are quite fair.

Threads and posts are free. There is no reason to ride someone else's coat tails when you can just as easily ask your own question.

Your post did not try to resolve the original poster's question. It diverted the attention AWAY from what was asked and onto your need. It was was not deleted - It was made into it's own thread so it would get the same attention and respect.
Jan 30 '10 #8
sanjib65
102 100+
You did not answer my main question:
But I have a question, is your forum not open for other good free tutorials or links? If someone like me wants to share his nice experience of learning elesewhere and give a reference to that link, it will be deleted immidiately?
Then what is basic of sharing knowledge in a FORUM?
Recently someone asked to know about making connections with MS Access Database. In response I posted this following link:

http://www.homeandlearn.co.uk/csharp/csharp_s12p4.html

You deleted the whole thread and instead posted two links of Bytes Tutorials on Database. Bytes tutorials are very good. I have gone through them, but is it mandatory here to read only these tutorials?
In forum guidelines I did not find any such dictum.

Best of Kuck
Jan 30 '10 #9
tlhintoq
3,525 Expert 2GB
Its rather up to the expert/moderator.

When a newbie posts a message whose sole content is to direct people to another site and thus away from this one, it looks like the new account was created just to steal traffic from this site.

When someone builds a history of posts that genuinely help others, and now and then that help comes from existing tutorials on other sites, then it is a reasonable post.
Jan 30 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Michael C | last post by:
Hi all, I'm now trying to update a status indicator via a Timer control on a worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly...
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...
1
by: jeff | last post by:
Greetings; Newbie here, please forgive my ignorance of the vb.net threading model. I am developing a windows service which is driven by a variable number of timers. All timers use the same...
2
by: jeff | last post by:
Greetings; Newbie here, please forgive my ignorance of the vb.net threading model. I am developing a windows service which is driven by a variable number of timers. All timers invoke the same...
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...
6
by: Dave | last post by:
I have a service that has 6 different threads. Each thread has a timer on it that elapses at about the same time (if not the same time). When the timer elapses I am trying to log a message by...
3
by: michdoh | last post by:
Hi All I'm looking for some help on creating a basic multi threaded application. i'n new to threads in this environment so for test purposes I've produced a very basic program. (which doesn't...
0
by: simplediscourse | last post by:
i'm trying to demonstrate timeslicing among equal high priority threads without putting threads to sleep. to do this i'm trying to run a timer while executing a very long loop sequence in order to...
4
by: gsimmons | last post by:
I've been researching multi-threaded WinForms apps and thread synchronization stuff for a couple days since I'm working on refactoring a multi-threaded GUI app at work and want to be sure it's...
2
by: Richard Cranium | last post by:
Hello, I have an interesting problem: I've got one thread in my program meant to maintain a timing subsystem and to do network I/O. It uses the select() system call to either wait for I/O or...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.