Do Timers operate on the UI thread, or do they have it's own thread?
I'm trying to assess the pros and cons for using a timer or a thread for a
certain application.
-Jerry 8 1117
The answer is: "It depends." There are several timers available.
System.Windows. Forms.Timer (from the Components section of the Toolbox)
executes in the STAThread of the UI.
System.Timers.T imer creates a separate thread, as does Sytem.Threading .Timer
(these are not exactly equivalent to each other).
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
On 14 Ago, 17:52, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
The answer is: *"It depends." *There are several timers available.
System.Windows. Forms.Timer (from the Components section of the Toolbox)
executes in the STAThread of the UI.
System.Timers.T imer creates a separate thread, as does Sytem.Threading .Timer
(these are not exactly equivalent to each other).
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netfor details and contact information.
Dear Dick,
I am new to this topic and interested.
I think that I have done some experiment by creating
System.Windows. Forms.Timer
within a thread and it worked fine.
Perhaps you are referring to the situation where one drags the
component on a form ?
Could you explain it better? I have the impression that there no need
to have a UI
to have the System.Windows. Forms.Timer work ... Is that right ? Nor it
necessarily
run on the UI thread...(?) Perhaps I am missing something ...
-P
On 2008-08-14, pamela fluente <pa***********@ libero.itwrote:
On 14 Ago, 17:52, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
>The answer is: *"It depends." *There are several timers available.
System.Windows .Forms.Timer (from the Components section of the Toolbox) executes in the STAThread of the UI.
System.Timers. Timer creates a separate thread, as does Sytem.Threading .Timer (these are not exactly equivalent to each other).
Dick
-- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. Seewww.hardand software.netfor details and contact information.
Dear Dick,
I am new to this topic and interested.
I think that I have done some experiment by creating
System.Windows. Forms.Timer
within a thread and it worked fine.
Perhaps you are referring to the situation where one drags the
component on a form ?
Could you explain it better? I have the impression that there no need
to have a UI
to have the System.Windows. Forms.Timer work ... Is that right ? Nor it
necessarily
run on the UI thread...(?) Perhaps I am missing something ...
-P
You are... The System.Windows. Forms.Timer requires a message pump on the
thread it is on to work. It is really a wrapper dealing with WM_TIMER
notification's. If you search, you will find that this is a common mistake
that people make when writing windows services - they will use a
System.Windows. Forms.Timer and then wonder why it never fires :)
--
Tom Shelton
On 14 Ago, 19:23, Tom Shelton <tom_shel...@co mcastXXXXXXX.ne twrote:
On 2008-08-14, pamela fluente <pamelaflue...@ libero.itwrote:
On 14 Ago, 17:52, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
The answer is: *"It depends." *There are several timers available.
System.Windows. Forms.Timer (from the Components section of the Toolbox)
executes in the STAThread of the UI.
System.Timers.T imer creates a separate thread, as does Sytem.Threading ..Timer
(these are not exactly equivalent to each other).
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netford etails and contact information.
Dear Dick,
*I am new to this topic and interested.
*I think that I have done some experiment by creating
System.Windows. Forms.Timer
*within a thread and it worked fine.
*Perhaps you are referring to the situation where one drags the
component on a form ?
Could you explain it better? I have the impression that there no need
to have a UI
to have the System.Windows. Forms.Timer work ... Is that right ? Nor it
necessarily
run on the UI thread...(?) * Perhaps I am missing something ...
-P
You are... *The System.Windows. Forms.Timer requires a message pump on the
thread it is on to work. *It is really a wrapper dealing with WM_TIMER
notification's. *If you search, you will find that this is a common mistake
that people make when writing windows services - they will use a
System.Windows. Forms.Timer and then wonder why it never fires :)
--
Tom Shelton- Nascondi testo citato
- Mostra testo citato -
hmm This is good to know. So I can create it but it will not work!
Very useful. Thanks a lot for pointing that out.
It's still rather misterious to me why a normal timer will not work
and
not sure why that "message pump" is needed... but I guess I will find
out
with practice ... :-)
-P
While it is possible for the forms Timer to work without a form, a message
pump is required... So, it isn't practical for you to attempt to use this
timer in an application that has no UI (IMO). The additional code needed is
too much to make it worthwhile.
This is one (of the) reason(s) that the System.Timers.T imer object is
available.
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
On 15 Ago, 18:41, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
While it is possible for the forms Timer to work without a form, a message
pump is required... So, it isn't practical for you to attempt to use this
timer in an application that has no UI (IMO). *The additional code needed is
too much to make it worthwhile.
This is one (of the) reason(s) that the System.Timers.T imer object is
available.
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netfor details and contact information.
Thank you. I have studied now the timers class and I think I am going
to replace most of my times with this one.
One thing that is *now* misterious to me is that, while I did not
realize the working of the "form" timer, is that
I do have a few timer defined several istances of a class that is not
attached to a GUI. And it does fire and works perfectly fine.
I am really puzzled about this and now I do not understand how is it
possible that those timers are working (?)
By some magic, looks like that .NET is able to "reconnect" those
timers to some form of the application. But I have no idea how this is
possible !?
Any idea?
-P
On 2008-08-15, pamela fluente <pa***********@ libero.itwrote:
On 15 Ago, 18:41, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
>While it is possible for the forms Timer to work without a form, a message pump is required... So, it isn't practical for you to attempt to use this timer in an application that has no UI (IMO). *The additional code needed is too much to make it worthwhile.
This is one (of the) reason(s) that the System.Timers.T imer object is available.
-- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. Seewww.hardand software.netfor details and contact information.
Thank you. I have studied now the timers class and I think I am going
to replace most of my times with this one.
One thing that is *now* misterious to me is that, while I did not
realize the working of the "form" timer, is that
I do have a few timer defined several istances of a class that is not
attached to a GUI. And it does fire and works perfectly fine.
I am really puzzled about this and now I do not understand how is it
possible that those timers are working (?)
By some magic, looks like that .NET is able to "reconnect" those
timers to some form of the application. But I have no idea how this is
possible !?
Any idea?
-P
They will work if:
1) they are in a windows forms application
2) the instances of the class containing them is created on the same thread as
the form that instantiated them...
They will work because there is a message pump on the thread that created
them.
--
Tom Shelton
On 15 Ago, 23:39, Tom Shelton <tom_shel...@co mcastXXXXXXX.ne twrote:
On 2008-08-15, pamela fluente <pamelaflue...@ libero.itwrote:
On 15 Ago, 18:41, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
While it is possible for the forms Timer to work without a form, a message
pump is required... So, it isn't practical for you to attempt to use this
timer in an application that has no UI (IMO). *The additional code needed is
too much to make it worthwhile.
This is one (of the) reason(s) that the System.Timers.T imer object is
available.
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netford etails and contact information.
Thank you. I have studied now the timers class and I think I am going
to replace most of my times with this one.
One thing that is *now* misterious to me is that, while I did not
realize the working of the "form" timer, is that
I do have a few timer defined several istances of a class that is not
attached to a GUI. And it does fire and works perfectly fine.
I am really puzzled about this and now I do not understand how is it
possible that those timers are working (?)
By some magic, looks like that .NET is able to "reconnect" those
timers to some form of the application. But I have no idea how this is
possible !?
Any idea?
-P
They will work if:
1) they are in a windows forms application
2) the instances of the class containing them is created on the same thread as
the form that instantiated them...
They will work because there is a message pump on the thread that created
them.
--
Tom Shelton- Nascondi testo citato
- Mostra testo citato -
Thanks Tom. Very helpful.
-P This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Amadej |
last post by:
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;
|
by: Vincent |
last post by:
Hi,
I was trying to do something in a Thread that starts by a
timer. I turn off the timer at the begining of the thread
incase it fires again when the thread is still running. Then
turn on the timer again before the thread finishes. To my
surprise, the timer never come alive again once it has been
turned of in the thread. To test the problem I made a simple
Windows Form project, put a Beep() in the timer. It supposed
to hear beep beep...
|
by: Brett |
last post by:
I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.
|
by: Philip Wagenaar |
last post by:
Hello,
I am using a timer object in my Windows Forms Application. Does the code in
..elapsed event run in a diffrent thread? If the interval is set to 10
milliseconds and the time to execute the code in the .elapsed event takes 1
secocond to complete, what happens?
1) Timer starts. 10 milliseconds later the code is executed and timer stops.
When code is done, 1 seconds later, the timer continues. 10 milliseconds
later the code is...
|
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 done.
// Instance variables
private Thread workerThread = null;
private System.Threading.Timer workerThreadMonitorTimer = null;
/// Code inside a button click event
ThreadStart workerThreadStart = new ThreadStart(DoWork);
| |
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 is running, a timer function keeps
executing every 250ms. The timer function does some real time data
processing and generates a bitmap which needs to be displayed on a
picture control. This is done using this->Invoke(...) in the form.
|
by: Beemer Biker |
last post by:
Unaccountably, I cannot re-enable a timer from an background thread. The
disable works fine, I just cannot get it to start back up. There is no
method "InvokeRequired" like there is for windows.forms.controls and I get
no error message about cross thread so I am not sure where the problem is.
I have a "SerialPoll_timer" that every second requests status from a device
on an RS232 port. I use this to determine if the device is on line. ...
|
by: =?Utf-8?B?anVhbg==?= |
last post by:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
|
by: winningElevent |
last post by:
This code C# is from online source but it was in console application so I modify to work on windows form just for learning on how to use threading.timer, but it doesn't work. Can anyone help me?
I would like the code below to display message to richtextbox while the timer object is not yet destroy so the main thread shouldn't run. When timer object is destroy, the main thread will start and display the last message, "Timer example done."
...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |