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

Timer question.

Hi,

Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.

How can we disable this timer(System.Threading.Timer) so that the time spent
in the callback method is not counted.

Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?

Kindly let me know.

Cheers,
Naveen.
Nov 17 '05 #1
4 4479
Hi Naveen,

To pauze the timer:

timer.Change(System.Threading.Timeout.Infinite,
System.Threading.Timeout.Infinite)

You need to change it back to the original interval to start the timer
again.

Ward
Naveen Mukkelli wrote:
Hi,

Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.

How can we disable this timer(System.Threading.Timer) so that the time spent
in the callback method is not counted.

Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?

Kindly let me know.

Cheers,
Naveen.

Nov 17 '05 #2
You might find System.Timers.Timer is better suited to this task.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:05**********************************@microsof t.com...
Hi,

Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.

How can we disable this timer(System.Threading.Timer) so that the time
spent
in the callback method is not counted.

Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?

Kindly let me know.

Cheers,
Naveen.

Nov 17 '05 #3
Hi bob,

but later on, I need to port the code to Compact Framework.
I guess System.Timers.Timer is not supported in Compact Framework.

Cheers,
Naveen.
"Bob Powell [MVP]" wrote:
You might find System.Timers.Timer is better suited to this task.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:05**********************************@microsof t.com...
Hi,

Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.

How can we disable this timer(System.Threading.Timer) so that the time
spent
in the callback method is not counted.

Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?

Kindly let me know.

Cheers,
Naveen.


Nov 17 '05 #4
One thing that you could do would be to set a flag when you enter your timer
handler. You will ignore any timer events while the flag is set, and reset
it when you finish your handler:
example:

// warning, I'm writing this "off the cuff", so there might be syntax errors
private bool TimerHandlerInProgress;
public void MyTimerCallback(object state)
{
lock(this)
{
if(this.TimerHandlerInProgress)
return; // ignore the timer elapse-- we are still handling the
last one
else
this.TimerHandlerInProgress = true;
}

try
{
// process your timer event here....
}
finally
{
// reset the handled flag
lock(this)
{
this.TimerHandlerInProgress = false;
}
}
}

"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:05**********************************@microsof t.com...
Hi,

Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.

How can we disable this timer(System.Threading.Timer) so that the time
spent
in the callback method is not counted.

Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?

Kindly let me know.

Cheers,
Naveen.

Nov 17 '05 #5

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

Similar topics

3
by: brian | last post by:
I have an ASP.Net application that uses impersonation. This works fine for accessing/executing the application. However, the app utilizes a timer, that when fired uses the <machine>ASPNET...
5
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a...
6
by: Steve Jorgensen | last post by:
I know quite well that this question falls into the category of "why does Access misbehave when I do unexpected things to its objects?", but I thought I'd ask anyway, and see if anyone knows. ...
1
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer...
10
by: Bob | last post by:
Okay, I've done this for years but now I'm going to question it just because this idea has been at the back of my head since I started using DotNet... My WinForms app queries a database every 60...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
12
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...
11
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...
16
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...
11
by: Anil Gupte/iCinema.com | last post by:
When I use this Dim instance As New Timer I get the error: Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. Yet, in the help section for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
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,...
0
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...

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.