473,748 Members | 6,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer Bug.

I think I've found a bug in the timer control.

I've got a class which uses a timer control.
It imports it from System.Windows. Forms

This timer ticks once a second, and then updates a
label which represents a clock on a form, to which the original class
has a reference. (MVC style)

If the user clicks and holds the X button on the form
being updated, the timer stops.
On moving the mouse cursor off of the X button and releasing
the timer continues, however my clock has not moved on.
I think this indicates they are on the same thread or something?

I'd imagine I can get round this by creating another thread,
but this seems wrong, surely a timer by nature should be on another
thread.

Just thought I'd mention it somewhere.
Hope thats ok!
Cheers
Chris.

Nov 16 '05 #1
8 3343
There is no guarantee that a timer is going to fire in exactly the Interval
property. Many factors can effect that such as other applications or
hardware events on your computer. Perhaps you should set a variable based
on Environment.Tic kCount to calculate timespans if you need some custom
clock operation or just use DateTime.Now to update your clock label on each
Elapsed event of your timer rather than counting on the interval of the
timer.

HTH

DalePres
MCAD, MCDBA, MCSE

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
I think I've found a bug in the timer control.

I've got a class which uses a timer control.
It imports it from System.Windows. Forms

This timer ticks once a second, and then updates a
label which represents a clock on a form, to which the original class
has a reference. (MVC style)

If the user clicks and holds the X button on the form
being updated, the timer stops.
On moving the mouse cursor off of the X button and releasing
the timer continues, however my clock has not moved on.
I think this indicates they are on the same thread or something?

I'd imagine I can get round this by creating another thread,
but this seems wrong, surely a timer by nature should be on another
thread.

Just thought I'd mention it somewhere.
Hope thats ok!
Cheers
Chris.

Nov 16 '05 #2
Nope, it's by design, the System.Windows. Forms.Timer is indeed on the
containing forms thread. There is also a System.Threadin g.Timer which is a
lightweight timer working off the threadpool, and System.Timers.T imer is
designed for use by worker threads.

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
I think I've found a bug in the timer control.

I've got a class which uses a timer control.
It imports it from System.Windows. Forms

This timer ticks once a second, and then updates a
label which represents a clock on a form, to which the original class
has a reference. (MVC style)

If the user clicks and holds the X button on the form
being updated, the timer stops.
On moving the mouse cursor off of the X button and releasing
the timer continues, however my clock has not moved on.
I think this indicates they are on the same thread or something?

I'd imagine I can get round this by creating another thread,
but this seems wrong, surely a timer by nature should be on another
thread.

Just thought I'd mention it somewhere.
Hope thats ok!
Cheers
Chris.

Nov 16 '05 #3
T.
Sean

I have have been having a somewhat similar problem. I have a thread which
runs an db.ExecuteWithR esultsAndMessag es(...) method asynchronously against a
SQLServer.Datab ase object. I start my timer just before the
db.ExecuteWithR esultsAndMessag es(...) method. But alas, the timer event (set
to fire every second) only fires after the second thread finishes. And the
SQL statements I tried take so far take at least a minute to complete.
Basically I want my app to echo to the user how many hh:mm:ss have lapsed
since execution commenced.

Much appreciate any helpful pointers!

"Sean Hederman" wrote:
Nope, it's by design, the System.Windows. Forms.Timer is indeed on the
containing forms thread. There is also a System.Threadin g.Timer which is a
lightweight timer working off the threadpool, and System.Timers.T imer is
designed for use by worker threads.

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
I think I've found a bug in the timer control.

I've got a class which uses a timer control.
It imports it from System.Windows. Forms

This timer ticks once a second, and then updates a
label which represents a clock on a form, to which the original class
has a reference. (MVC style)

If the user clicks and holds the X button on the form
being updated, the timer stops.
On moving the mouse cursor off of the X button and releasing
the timer continues, however my clock has not moved on.
I think this indicates they are on the same thread or something?

I'd imagine I can get round this by creating another thread,
but this seems wrong, surely a timer by nature should be on another
thread.

Just thought I'd mention it somewhere.
Hope thats ok!
Cheers
Chris.


Nov 16 '05 #4
Which Timer are you using? If the timers on it's own thread use
System.Timers.T imer, otherwise use System.Threadin g.Timer.

"T." <T@discussions. microsoft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Sean

I have have been having a somewhat similar problem. I have a thread which
runs an db.ExecuteWithR esultsAndMessag es(...) method asynchronously
against a
SQLServer.Datab ase object. I start my timer just before the
db.ExecuteWithR esultsAndMessag es(...) method. But alas, the timer event
(set
to fire every second) only fires after the second thread finishes. And the
SQL statements I tried take so far take at least a minute to complete.
Basically I want my app to echo to the user how many hh:mm:ss have lapsed
since execution commenced.

Much appreciate any helpful pointers!

"Sean Hederman" wrote:
Nope, it's by design, the System.Windows. Forms.Timer is indeed on the
containing forms thread. There is also a System.Threadin g.Timer which is
a
lightweight timer working off the threadpool, and System.Timers.T imer is
designed for use by worker threads.

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
>I think I've found a bug in the timer control.
>
> I've got a class which uses a timer control.
> It imports it from System.Windows. Forms
>
> This timer ticks once a second, and then updates a
> label which represents a clock on a form, to which the original class
> has a reference. (MVC style)
>
> If the user clicks and holds the X button on the form
> being updated, the timer stops.
> On moving the mouse cursor off of the X button and releasing
> the timer continues, however my clock has not moved on.
> I think this indicates they are on the same thread or something?
>
> I'd imagine I can get round this by creating another thread,
> but this seems wrong, surely a timer by nature should be on another
> thread.
>
> Just thought I'd mention it somewhere.
> Hope thats ok!
> Cheers
> Chris.
>


Nov 16 '05 #5
Thanks I put in a the System.Timer timer and it worked.
Was following a slightly questionable tutorial off the net which
recommended the forms one.
Still Seems a strange design to me but there we go. Surely most
people that place a timer control are there form aren't going to
realise this?

Cheers
Chris

Nov 16 '05 #6
"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Thanks I put in a the System.Timer timer and it worked.
Was following a slightly questionable tutorial off the net which
recommended the forms one.
Still Seems a strange design to me but there we go. Surely most
people that place a timer control are there form aren't going to
realise this?
For most form applications the forms timer is perfectly acceptable. For
example, consider if you want you application to check for emails every five
minutes. It doesn' have to be EXACTLY five minutes, it can be close to that.
Since your main UI thread shouldn't be doing massive long-term processing
the timer shouldn't be out by too much. A big advantage of the forms timer
is that you don't add threads (and therefore context switches) to your app,
which makes it a bit more lightweight. Finally, it was apparently decided to
duplicate the behaviour of the VB6 Timer control.

Cheers
Chris

Nov 16 '05 #7
While the System.Timer timer is working for you, keep in mind that there is
still no guarantee that it will fire in one second. Any other process could
cause that to be delayed. Any timer is not a good choice for keeping clock
time. Either the DataTime structure should be used or create your own
functionality counting ticks.

DalePres

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Thanks I put in a the System.Timer timer and it worked.
Was following a slightly questionable tutorial off the net which
recommended the forms one.
Still Seems a strange design to me but there we go. Surely most
people that place a timer control are there form aren't going to
realise this?

Cheers
Chris

Nov 16 '05 #8
Cheers. thats actually what I'm doing although I didn't mention
it in the orinal post. The timer produces a tick.
On the tick it updates a DateTime.
However accuracy is not really an issue here, as it's only a test tool
(Was just being picky!).

Did have to do something recently that did have to be accurate
down to about 1ms. involving a timer card dos, and a 1991 Borland c++
compiler and more interrupts than the poor machine had available.
All I can say is never again!

DalePres wrote:
While the System.Timer timer is working for you, keep in mind that there is still no guarantee that it will fire in one second. Any other process could cause that to be delayed. Any timer is not a good choice for keeping clock time. Either the DataTime structure should be used or create your own functionality counting ticks.

DalePres

"theinvisibleGh ost" <th************ ***@yahoo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Thanks I put in a the System.Timer timer and it worked.
Was following a slightly questionable tutorial off the net which
recommended the forms one.
Still Seems a strange design to me but there we go. Surely most
people that place a timer control are there form aren't going to
realise this?

Cheers
Chris


Nov 16 '05 #9

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

Similar topics

13
7494
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
6
2877
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 TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
9
7285
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null; Let's declare a constant Int32 m_TimePeriod = 10000;
7
2151
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: ------------- ....some code... Dim usersTimers(4) As System.Windows.Forms.Timer For i = 0 To 4
2
4065
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: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
12
5528
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
8
6860
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have never used this timer. I used the documentation from Microsoft as a guide, but I cannot get this timer to work. Protected Overrides Sub OnStart(ByVal args() As String) Dim myTimer As New TimerState()
8
2663
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next Elapse. Is there any way -- whether in my code, or in the O/S -- to determine when a Timer is scheduled to Elapse?
11
2600
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
16
3256
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
0
8987
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, 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...
0
8826
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,...
0
9534
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, 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...
0
9366
jinu1996
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...
0
9241
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 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...
0
6073
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();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
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
3
2211
bsmnconsultancy
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...

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.