PRR 750
Recognized Expert Contributor
Use a System.Timers.T imer. 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."
9 7641
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?
PRR 750
Recognized Expert Contributor
Thread and Timers are different.Timer s are used to execute certain tasks after a defined interval. Threading is execution of tasks simultaneously. Some timers internally use threads( System.Timers.T imer 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.T imer
2. System.Windows. Forms.Timer
3. System.Threadin g.Timer
Each application has a pool of threads, normally around 20-50 called threadpool. Threadpool are background threads. System.Timers.T imer in its elapsed event spawns new threads( from threadpool).
Many thanks PRR, nicely explained but I wanted to know another thing. Suppose, in an data application using AJAX when we use System.Thresdin g.Thread.Sleep( 3000) and pause the UpdateProgress for 3 seconds, does it not do something(suppo se 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.
tlhintoq 3,525
Recognized Expert Specialist
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.
tlhintoq 3,525
Recognized Expert Specialist
System.Thresdin g.Thread.Sleep( 3000) and pause the UpdateProgress for 3 seconds, does it not do something(suppo se 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. -
DateTime dtBailout = DateTime.Now.AddSeconds(3);
-
while (DateTime.Now < dtBailout)
-
{
-
Application.DoEvents();
-
}
-
// Continue doing something
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
tlhintoq 3,525
Recognized Expert Specialist
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.
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
tlhintoq 3,525
Recognized Expert Specialist
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 how to implement a separate worker
thread or asynchronous delegate that changes the label contents based on the
Timer control's ticks. Are there any good examples out there and can you
point me to one or two?
Thanks,
|
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 ThreadPool thread.
And that is exactly what MS VIsual Studio shows.
But when I run Processexplorer or Taskmanager I see 2 additional
threads, after a while another 2 additional threads. With the 3 threads
at start time we have totally 7 threads.
|
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 event
handler, and each invocation sends a command to another
service. What are the threading considerations given
this scenario?
|
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
event handler, and each invocation sends a command to
another service. What are the threading considerations
given this scenario?
|
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 which I create in my web service and
the culture (but not uiCulture) revert to the system default!
Does anyone know if this is a bug and how to get around it?
asp.net 1.1 web service
| |
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 writing to a text
file. The problem is that not every thread is able to log its message.
I thought it was because each thread is trying to use the same
resource. So i put in mutex.waitone() and released the mutex at the
end of the method. It...
|
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 work)
Calling the 2 methods directly has the desired effect however when I
try to impelment them as threads nothing happens.
|
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 get the processor to round-robin through the high priority threads. here's what i have:
static void Main(string args)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new...
|
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
rock solid/thread-safe. I've seen all the posts about using BeginInvoke
to have worker threads interact with the UI. My question is this:
I created a plain old Windows Form application (VS.NET 2005) with a
blank form, built it (release build), ran...
|
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 "time out" and "handle" some arbitrary "event".
The timeout value for select() is calculated off of a list of "active
timers" which contains all the necessary information to correctly guess
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |