473,809 Members | 2,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to stop a timer at a given time in C#?

1 New Member
how to stop a timer at a given time? say 10mins?
Feb 23 '12 #1
2 1750
GaryTexmo
1,501 Recognized Expert Top Contributor
Get the value of DateTime.Now before you start it and store it somewhere like a variable called startTime. Then check to see if (DateTime.Now - startTime).Tota lMinutes is greater than 10.

(NOTE: Subtracting, or adding, two DateTime values results in a TimeSpan object)
Feb 23 '12 #2
GaryTexmo
1,501 Recognized Expert Top Contributor
I should also mention, if your timer is ticking every X seconds/minutes but you want to turn it off after exactly 10, you could always use a second timer. Create it, set the interval to whatever your timeout is, then turn both timers off when the second timer ticks.

Whatever works best for you.
Feb 23 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
17916
by: CrystalDBA | last post by:
I am using SQL Server 2000. I need to query my database for all the contracts that came in during a certain time frame (user is prompted for reportingperiodid). Table - Periods Fields - Reporting Period id int Reporting Period desc varchar(30) Reporting Period Begin Date datetime Reporting Period End Date datetime
1
1755
by: Lei Guangfu | last post by:
Hi, I have a program need to check the value of a application available, and then decide whether to execute codes followed. In order to achieve this purpose, I use DO WHILE loop to judge the value, if the value meet the condition clause, program will exit the loop. But this DO WHILE loop consumes too much CPU resource. Now my question is whether a possible way to pause a process for a given time such as one minute? Anyone can give me...
1
334
by: Lei Guangfu | last post by:
Hi, I have a program need to delay for a given time, I use DO WHILE loop to achieve this goal, but this method consumes too much CPU resource. So I want to find a way to pause a process for a given time such as one minute. Anyone can offer me some guides? Thanks in advance. For better understanding the scenario, please refer to following codes: Public Function BeginConnection() As Boolean Try
7
2407
by: J e r | last post by:
I'm a novice using VB .NET . I'm trying to use 2 files to read a line write the line and get the run time error "..exception of type 'System.IO.IOException.....additional information: File already open." It seems the error message is telling me VB can have only 1 file open at a time. Tell me that's not true and where I'm going wrong, please. The code is:
1
1689
by: dponce | last post by:
Best regards to all, I am new to this form and site, not to mention I am a beginning MS Access developer. This software came install on my laptop and seems to be pretty cool programming software. I have been playing around with this for 2 months and have been putting together some simple data bases just to learn what I can. What I am needing help in is I am trying to find away that I can tell the program to delete all the records found...
2
8710
by: Mathias Weyel | last post by:
Hi there, I have time-of-day spans presented as strings and want to check, if, at a given time, I am within such a time span. Example: Timespan-string is given as follows: "09:00 , 16:00" A function should now return true if the current time of day is between 9:00 and 16:00 and false otherwise.
2
1553
by: Elliot | last post by:
My program use a timer to 'refresh' a method "a" every several seconds, private void a(object sender, EventArgs eArgs) { Timer T1 = new Timer(); T1.Interval = 100000; T1.Start(); T1.Tick += new EventHandler(b); Timer T2 = new Timer();
1
7419
by: sasasasa | last post by:
How can I loop through each date in a given time period so that I can add those dates as a column name in a table. I want to create datatable with the person's name and hours he worked in a given time period. The user will select the dates and I want to show each day/date in that table as a column name. I have no idea how to do it. Please help.
3
3572
by: ashimasingh | last post by:
hello , i need a help regarding python programming: basically i need to find out times between the start and the stop time. Here is what i have tried--- s = raw_input('enter first time (hh:mm:ss ):') z = raw_input('enter the second time (hh:mm:ss):')
0
9722
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
10378
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...
1
10391
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,...
0
10121
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
9200
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
6881
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
5550
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
4333
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
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.