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

Timer stopping in c#

hie all.

i am new to c#, ma y you please help me on how to stop a timer. i created a timer during design time.

i am looking at some sources here and they say i must use
Expand|Select|Wrap|Line Numbers
  1. timer.stop();
but when i try to use it i am getting an error saying
Expand|Select|Wrap|Line Numbers
  1. "error CS1061: 'System.Windows.Forms.Timer' does not contain a definition for 'stop' and no extension method 'stop' accepting a first argument of type 'System.Windows.Forms.Timer' could be found (are you missing a using directive or an assembly reference?)
  2. "
  3.  
what i am trying to accomplish is that my dialog must close after a certain time, if i use
Expand|Select|Wrap|Line Numbers
  1. timer.Enabled = false;
it is not stopping the timer,

i wanted the timer to stop completely when i click a button on that dialog and i am puttting a
Expand|Select|Wrap|Line Numbers
  1. timer.enabled =  false 
on the click event

thanks in advance
Dec 8 '11 #1
2 5361
Fr33dan
57
The Stop function of the Timer class does not follow the typical "first letter of methods is lowercase" practice. That being said, setting timer.Enabled to false should stop it anyway. Is still running or are you just getting a single fire after the fact? Or maybe due to the way you programmed the dialog you're accessing the wrong timer?
Dec 8 '11 #2
adriancs
122 100+
you may try this:
Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     Timer timer1;
  4.     Timer timer2;
  5.     public Form1()
  6.     {
  7.         InitializeComponent();
  8.         timer1 = new Timer();
  9.         timer1.Interval = 3000;
  10.         timer1.Tick += new EventHandler(timer1_Tick);
  11.         timer2 = new Timer();
  12.         timer2.Interval = 200;
  13.         timer2.Tick += new EventHandler(timer2_Tick);
  14.     }
  15.  
  16.     private void button1_Click(object sender, EventArgs e)
  17.     {
  18.         timer1.Start();
  19.         timer2.Start();
  20.     }
  21.  
  22.     void timer2_Tick(object sender, EventArgs e)
  23.     {
  24.         this.label1.Text += "\nHello World";
  25.     }
  26.  
  27.     void timer1_Tick(object sender, EventArgs e)
  28.     {
  29.         timer1.Stop();
  30.         timer2.Stop();
  31.         MessageBox.Show("Stop saying hello.");
  32.     }
  33. }
Dec 9 '11 #3

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

Similar topics

1
by: Geoff | last post by:
Hey.. I'm having problems with stopping this timer from outside the 'runTimer()' class.. i have no problems calling 'cancel()' from inside the run() method but I want to be able to stop the Timer...
3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
5
by: Mike P | last post by:
With the VB6 timer, it was simply a matter of setting Enabled = true to start the timer, and Enabled = false to stop the timer. With C# you also have Start and Stop methods. To get the same...
3
by: chrisdevey | last post by:
Is there any way to make a System.Timers.Timer adjust for daylight savings time change? In a long running process I set a timer as follows for a daily expiration: _myTimer = new...
3
by: Scott H | last post by:
Hello, I'm having a go at writing my first Windows Service in VB.NET and I'm having a problem. I have it installed ok and started the service sucessfully, I can stop it, and restart it fine, the...
6
by: Michael C | last post by:
I've created a timer object and set it running without keeping a reference to it and not stopping it. Shouldn't the garbage collector pick up that there's no reference to the timer, call finalize...
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...
8
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...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.