473,725 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

makinmg sure Timer doesn't execute again while running...

VMI
I have several procedures that are executed when the Timer.Tick event is run.
How can I make sure that those procedures are not executed again (by the
Tick event) if the previously-called procedures (also called by the same Tick
event) are still running?
Is it possible to condition it using a bool? For example, just before
running the first procedure activated by the Timer, bool iSComplete will
equal false. When the Timer is run again after X seconds, it'll check
iSComplete. If iSComplete is false, then it won't run again. If not, it'll
run.
The problem is that I tried this, but it displayed some erratic behavior. I
think it has to do with the threading.

Thanks.
Nov 17 '05 #1
1 1663
If I understand the problem correctly...
All you have to do (and should always do to avoid re-entrance) is
disable the timer when the procedure is entered and re-enable it when
exiting. You should also follow this model when executing button click event
methods to avoid the user clicking the button while the button code is
executing.

Gregory McCallum, MCSD
gm*******@honov i.com
"VMI" wrote:
I have several procedures that are executed when the Timer.Tick event is run.
How can I make sure that those procedures are not executed again (by the
Tick event) if the previously-called procedures (also called by the same Tick
event) are still running?
Is it possible to condition it using a bool? For example, just before
running the first procedure activated by the Timer, bool iSComplete will
equal false. When the Timer is run again after X seconds, it'll check
iSComplete. If iSComplete is false, then it won't run again. If not, it'll
run.
The problem is that I tried this, but it displayed some erratic behavior. I
think it has to do with the threading.

Thanks.

Nov 17 '05 #2

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

Similar topics

3
2964
by: Lloyd Sheen | last post by:
I have a problem where I cannot read (all the time) a file when caught by the FileSystemWatcher. What I have done to get past this is create an array of events (when I receive one I add it to the list). I then enable a timer which will attempt to process the first one in the list. The timer code is never executed. There is a handles clause on the timer and using the debugger I have watched the code for the FileSystemWatcher execute. ...
3
16904
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects interval property inside the event handler? Example follows: Constructor: mTimer = new System.Timers.Timer(20000); mTimer.AutoReset = false;
7
33583
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows form and it works fine, but in the service: nothing. .... this.components = new System.ComponentModel.Container(); this.tmrTimer = new System.Windows.Forms.Timer(this.components); // // tmrTimer //
8
2783
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
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;
11
7562
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...
3
1693
by: Steven Nagy | last post by:
Hi all, I have a problem where I am developing a site for a client that needs to perform a certain analysis against the database every hour, on the hour. The problem is that the hosting company will only allow a standard ASP.NET web app to be run on their server; no EXE's can be run. So I am not sure how I would implement functionality to run the required service. You see, its theoretically possible that no one would use the site on a
8
1579
by: Curious | last post by:
Hi, Are there known issues with running two timers at the same time? I have bumped into a problem - I start a first timer at an interval of 5 seconds. 15 seconds later, I start a second timer at 15 seconds interval. That's when things start to fail with the first timer (it doesn't seem to do what it should do). My seconds question: Is there a way to create a timer for a fixed time
8
3370
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location on a network for files and then copies these files to another location (on the network) AND then updates a record in the database. The file copying is performed before the database update because the file system is not transactional. The code...
0
8747
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
9392
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
9246
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
9091
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
8069
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, 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...
0
5997
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
4505
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...
1
3211
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
2150
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.