473,803 Members | 3,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timer

Hi Im using
System.Timers.T imer myTimer = new System.Timers.T imer();
myTimer.Elapsed += new ElapsedEventHan dler(onTimer);
myTimer.Interva l = 1000;
myTimer.Start() ;
and getting error onTimer does not exist in the current context. Any
Ideas
Regards Robert

May 23 '06 #1
8 3563
I suppose this is im method body.
try to declare myTimer in class not in method body

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 23 '06 #2
Well, where /is/ onTimer?

Marc
May 23 '06 #3
try this

class Myclass: Form //probably
{
System.Timers.T imer myTimer;

private void button1_Click(o bject sender, EventArgs e)
{
myTimer = new System.Timers.T imer();
myTimer.Elapsed += new
ElapsedEventHan dler(MyTimer_El apsed);
timer1.Tick+=ne w EventHandler(ti mer1_Tick);
myTimer.Interva l = 1000;

}
void MyTimer_Elapsed (object sender, System.Timers.E lapsedEventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 23 '06 #4
3 big problems with this suggestion:

1) System.Timers.T imer calls back on a different thread (requiring
additional handling)
2) You should dispose the Timer (either forms or system)
3) Because if you don't do 2 it keeps firing forever ;-p

Following illustrates this using 2 timers - one System.Timers and one
System.Windows. Forms; watch the debug output and see the threads being used;
also note that if you get rid of the Dispose override then it keeps firing
even after the end of the form - which can lead to the event trying to
access a disposed form.

Marc

using System;

static class Program {
public class MyForm : System.Windows. Forms.Form {
private System.Componen tModel.IContain er components = null;
private System.Timers.T imer timer1;
private System.Windows. Forms.Timer timer2;
public MyForm() {
components = new System.Componen tModel.Containe r();
timer1 = new System.Timers.T imer(1000);
timer2 = new System.Windows. Forms.Timer(com ponents);
timer2.Interval = 1000;
components.Add( timer1); // add timer1
timer1.Elapsed += Tick;
timer2.Tick += Tick;
timer1.Start();
timer2.Start();
}
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Disp ose();
}
base.Dispose(di sposing);
}
private void Tick(object sender, EventArgs args) {
System.Threadin g.Thread thread =
System.Threadin g.Thread.Curren tThread;
System.Diagnost ics.Debug.Write Line(sender.Get Type().FullName ,
thread.ManagedT hreadId.ToStrin g() + "[" + (thread.IsThrea dPoolThread ?
"(pool)" : thread.Name) + "]");
}

}
static void Main() {
System.Threadin g.Thread.Curren tThread.Name = "UI";
using (MyForm form = new MyForm()) {
form.ShowDialog ();
}
System.Windows. Forms.MessageBo x.Show("Done");
}

}
May 23 '06 #5
Thanks for all your replys. I have to admit this has gone beyond my
level of understanding. Ive not long started using c#. What Im trying
to do is every 30sec or so, is update a textbox with what number record
I on. From what ive read on the timer, it started of easy, but I cant
work out wether I need to create a class, then add to project, or use
within my program. Thanks again.
Regards Robert

May 23 '06 #6
you're right

Thank you

Regards,
Galin Iliev[MCSD.NET]
www.galcho.com

May 23 '06 #7
This is going to sound sarcastic, but I certainly don't mean it any way but
to be genuinely helpful. Bookmark the following in your browser:

http://msdn.microsoft.com/library/en...asp?frame=true

That is the URL of the online Microsoft .Net SDK, and it contains everything
you need to know. The reason I'm giving you such a general reference is due
to your statements that you've just started out using c#, and of course, the
nature of your question. Everyone starts out at the beginning, and mastery
of .Net programming is a long and difficult task.

It's one thing to understand the syntax of a programming language. It's
another thing altogether to understand the vast mountain of tools and
technologies that the .Net platform makes avaialable to you as a developer.
I've been a developer for more than a dozen years, and I still probably
spend a total of an hour a day with my head buried in the .Net SDK and other
resources.

..Net programming is a lot more than writing code. It is the employment of
Object-oriented, event-driven programming and design principles with a
starter kit of tens of thousands of ready-built classes to work with. I am
only familiar with about half of them at this point, and I've been using
them for about 5 or 6 years now. It's intimidating! But the SDK also
contains a large number of articles, tutorials, and sample code to help you
get through it. Start small, start from the beginning, and you might want to
start with some of the "Starter Kits" in the SDK. Otherwise, you'll drive
yourself crazy and likely become discouraged and give up. That would not be
a good thing. .Net programming is very rewarding in the long run! But even
for those of us who love it, it's always a "love-hate" relationship.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

<Ro********@yah oo.co.uk> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
Thanks for all your replys. I have to admit this has gone beyond my
level of understanding. Ive not long started using c#. What Im trying
to do is every 30sec or so, is update a textbox with what number record
I on. From what ive read on the timer, it started of easy, but I cant
work out wether I need to create a class, then add to project, or use
within my program. Thanks again.
Regards Robert

May 23 '06 #8
On Tue, 23 May 2006 12:37:51 -0400, "Kevin Spencer"
<ke***@DIESPAMM ERSDIEtakempis. com> wrote:
This is going to sound sarcastic, but I certainly don't mean it any way but
to be genuinely helpful. Bookmark the following in your browser:

http://msdn.microsoft.com/library/en...asp?frame=true

That is the URL of the online Microsoft .Net SDK, and it contains everything
you need to know. The reason I'm giving you such a general reference is due
to your statements that you've just started out using c#, and of course, the
nature of your question. Everyone starts out at the beginning, and mastery
of .Net programming is a long and difficult task.

It's one thing to understand the syntax of a programming language. It's
another thing altogether to understand the vast mountain of tools and
technologies that the .Net platform makes avaialable to you as a developer.
I've been a developer for more than a dozen years, and I still probably
spend a total of an hour a day with my head buried in the .Net SDK and other
resources.

.Net programming is a lot more than writing code. It is the employment of
Object-oriented, event-driven programming and design principles with a
starter kit of tens of thousands of ready-built classes to work with. I am
only familiar with about half of them at this point, and I've been using
them for about 5 or 6 years now. It's intimidating! But the SDK also
contains a large number of articles, tutorials, and sample code to help you
get through it. Start small, start from the beginning, and you might want to
start with some of the "Starter Kits" in the SDK. Otherwise, you'll drive
yourself crazy and likely become discouraged and give up. That would not be
a good thing. .Net programming is very rewarding in the long run! But even
for those of us who love it, it's always a "love-hate" relationship.

Very sound advice :)

Steve

http://www.pretty-vacant.co.uk
May 23 '06 #9

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

Similar topics

13
7502
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
6
2886
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
9
7290
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;
7
2153
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: ------------- ....some code... Dim usersTimers(4) As System.Windows.Forms.Timer For i = 0 To 4
2
4069
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
12
5538
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 directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
8
6867
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 never used this timer. I used the documentation from Microsoft as a guide, but I cannot get this timer to work. Protected Overrides Sub OnStart(ByVal args() As String) Dim myTimer As New TimerState()
8
2666
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next Elapse. Is there any way -- whether in my code, or in the O/S -- to determine when a Timer is scheduled to Elapse?
11
2611
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 library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
16
3258
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 do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
0
9700
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
9564
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
10546
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...
1
10292
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
5498
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...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
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
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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.