473,320 Members | 1,810 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.

Best way to stop and restart a System.Timers.Timer

Hi,

What is the best way to release all resources holded by the Timer
(myTimer from class System.Timers.Timer)?

Is it:
1- myTimer.dispose
2- myTimer.enabled = false
3- myTimer.close

I want to have the timer set to nothing so I can recreate a new one, I
want to do this in a second step:

myTimer = New System.Timers.Timer
AddHandler myTimer.Elapsed, AddressOf ListenToRequest
myTimer.Interval = 100
myTimer.Enabled = True

I am asking this because it seem that the timer loop a couple of time
before being stopped, and raising errors by the way.
This is my original code:
myTimer.Dispose()
myTimer = New System.Timers.Timer
AddHandler tmrClientQwery.Elapsed, AddressOf ListenToRequest
myTimer.Interval = 100
myTimer.Enabled = True

Thank you very much

Nov 20 '05 #1
2 8910
The Timer.Enabled actually destroys the timer internally anyway. The extra
timer event's you're seeing are probably due to messages that are in the
queue. This can happen if you do a lot of processing in the timer tick
handler such as drawing on screen or disc access.

A more accurate and reliable timer can be found in System.Threading. The
dlegate for this timer is called directly and there are never any messages
hanging around in the queue.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"User" <gu***@guest.com> wrote in message
news:x3dHc.9484$Rf.5781@edtnps84...
Hi,

What is the best way to release all resources holded by the Timer
(myTimer from class System.Timers.Timer)?

Is it:
1- myTimer.dispose
2- myTimer.enabled = false
3- myTimer.close

I want to have the timer set to nothing so I can recreate a new one, I
want to do this in a second step:

myTimer = New System.Timers.Timer
AddHandler myTimer.Elapsed, AddressOf ListenToRequest
myTimer.Interval = 100
myTimer.Enabled = True

I am asking this because it seem that the timer loop a couple of time
before being stopped, and raising errors by the way.
This is my original code:
myTimer.Dispose()
myTimer = New System.Timers.Timer
AddHandler tmrClientQwery.Elapsed, AddressOf ListenToRequest
myTimer.Interval = 100
myTimer.Enabled = True

Thank you very much

Nov 20 '05 #2
Thanks ,

I tried this System.Threading.Timer. Is it possible that it
automatically create many threads that run the code in the elapsed event?

How can I be sure that I have only one thread under this timer?

Thank you!

Bob Powell [MVP] wrote:
The Timer.Enabled actually destroys the timer internally anyway. The extra
timer event's you're seeing are probably due to messages that are in the
queue. This can happen if you do a lot of processing in the timer tick
handler such as drawing on screen or disc access.

A more accurate and reliable timer can be found in System.Threading. The
dlegate for this timer is called directly and there are never any messages
hanging around in the queue.


Nov 20 '05 #3

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

Similar topics

10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
3
by: Tom | last post by:
When using system.timers.timer, which should one use to start/stop the timer? Start/Stop, or Enabled=True/False? If what I read is true, both really do the same thing, so I don't know if there is...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
10
by: DaTurk | last post by:
Hi, I'm creating an application that will need to use a timer to do a static method call every second. My question, is what would be the best timer to use? I know there are several, but I'd...
7
by: Daniele Piccinini | last post by:
Hallo, I've writed a C# windows service in VS 2003. This service use a System.Timers.Timer to periodically call some functions of a web service. ( Some of this functions required minutes to be...
2
by: BobAtVandy | last post by:
I'll greatly appreciate any help on this. Actually 2 questions: 1. I believe I need to use the Windows timer System.Timers.Timer . The examples I find on the web all access that timer by...
8
by: Lemune | last post by:
Hi, I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.