473,624 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic timer reference problem

hi,
can somebody explain this problem? it's driving me crazy!
i have a requirement to dynamically create a variable quantity of timers
with associated start button based on the contents of a database. if i
create system timers dynamically, i cannot reference them from the start
button click event handler. the build error is ' <timer name> not
declared>
----
however, if i declare the system timers outside runtime code, everything
works fine! ....but that doesn't do me much good since i dont' know how
many timers i'll need at design time.
gotta be syntax or something. thanks in advance. kris
---- THIS WORKS -----

Public Class Form1
Inherits System.Windows. Forms.Form
Private t As New System.Timers.T imer 'TIMER DECLARED HERE
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArg s)
t.Enabled = True
End Sub


---- DOES NOT BUILD ----

Public Class Form1
Inherits System.Windows. Forms.Form
'timer declaration added

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
dim t As New System.Timers.T imer 'TIMER DECLARED HERE
add elapsed time handler

'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArg s)
t.Enabled = True !!!!!!! CAUSES BUILD ERROR (t not declared)
End Sub


Nov 21 '05 #1
3 1965
You need something to hold your timer in. So this works. You probably want
to have "t" become an arraylist if it is going to be a dynamic amount of
timer objects you want to hold. Hope it helps.

Chirs

Public Class Form1
Inherits System.Windows. Forms.Form

dim t As System.Timers.T imer
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
t = New System.Timers.T imer 'TIMER DECLARED HERE
add elapsed time handler
'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArg s)
t.Enabled = True
End Sub

"Kris Palmer" <kr************ @REMOVEyahoo.co m> wrote in message
news:Xn******** *************** ***********@130 .81.64.196...
hi,
can somebody explain this problem? it's driving me crazy!
i have a requirement to dynamically create a variable quantity of timers
with associated start button based on the contents of a database. if i
create system timers dynamically, i cannot reference them from the start
button click event handler. the build error is ' <timer name> not
declared>
----
however, if i declare the system timers outside runtime code, everything
works fine! ....but that doesn't do me much good since i dont' know how
many timers i'll need at design time.
gotta be syntax or something. thanks in advance. kris
---- THIS WORKS -----

Public Class Form1
Inherits System.Windows. Forms.Form
Private t As New System.Timers.T imer 'TIMER DECLARED HERE
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArg s)
t.Enabled = True
End Sub


---- DOES NOT BUILD ----

Public Class Form1
Inherits System.Windows. Forms.Form
'timer declaration added

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
dim t As New System.Timers.T imer 'TIMER DECLARED HERE
add elapsed time handler

'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArg s)
t.Enabled = True !!!!!!! CAUSES BUILD ERROR (t not declared)
End Sub

Nov 21 '05 #2

"Kris Palmer" <kr************ @REMOVEyahoo.co m> wrote
i have a requirement to dynamically create a variable quantity of timers


If you need to time an egg boiling on the stove, and toast in the toaster,
as well as a pizza in the oven, does that mean you need to use 3 clocks
to ensure you can time them all?

Of course not, you'd use one clock to time them all, and only keep
track of the interval times required. While it may be convenient to have
a couple timers running, I would think in your case, with the need of some
variable number of timers, that you devise a means to use one timer, and
several classes that all watch the clock for their own intervals to elapse....

The reasoning is that adding multiple classes use less system resources
than adding new server based timers.

Just a suggestion!
LFS
Nov 21 '05 #3
Hi Larry,

We in Europe have not such advanced appliances as you there, we just have on
every one a clock.

:-)

Cor
Nov 21 '05 #4

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

Similar topics

4
3371
by: Richard Abraham | last post by:
I have created a new class ServiceTimer based upon the .NET System.Timers.Timer class. This has a new property CollectionIntervalMinutes which I expected to be added to the 'Behavior' section of the class properties and also to be available as a 'Dynamic' property so that I could control it from the application config file. The new property is not shown, but the properties inherited from the base class are I cannot find any reference to how...
4
276
by: ALI-R | last post by:
there is a timer on Form1 and I want to change it from Form2,how can I do that?? thanks
2
1717
by: Benjamin | last post by:
Hi, I am having a problem enabling a timer in my class. I have attached some sample pseudo code (see "Sample code illustrating issue") so you can see what I am talking about. Whats the issue? ================ I am unable to pause the timer when a timed event is thrown due to my event handling having a private scope. If I make the scope public all works as expected.
5
7800
by: Dave | last post by:
I trying to setup a time. The following code is in a function, Timer stateTimer = new Timer(ab(), null, 1000, 1000); I have included using System.Threading; at the begining of my code. When I try to compile I receive the error,
5
8510
by: theinvisibleGhost | last post by:
I'm having a problem that occurs at random in my app. I get an exception "Cannot Access a disposed object" In MSCorLib when calling boolean Change (int32, int32) Stack trace reveals System.Threading.Timer.Change(Int32, int32) at Systems.Timers.UpdateTimer() at System.Timers.Timer.set_Interval(double value)
8
3167
by: Jerry Spence1 | last post by:
I am trying to create timers on demand by doing the following: Dim NewTimer As New System.Timers.Timer NewTimer.Interval = 10000 AddHandler NewTimer.Elapsed, AddressOf Timeup NewTimer.Enabled = True NewTimer.Start() My problem then happens in the TimeUp routine
5
12210
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
0
1592
by: Bruce | last post by:
Hi I have a question on using System.Threading.Timer. I understand that in order for the timer to work, I need to store a reference to the timer so that it does not get garbage collected. In my application, I create a lot of timers - so I have a StoreTimer class that has a method AddTimer that other classes can call. Inside AddTimer, I create timers and store references to them inside a class level hashtable. My problem is when to...
4
2324
by: =?Utf-8?B?R29yZnk=?= | last post by:
Hey everyone. This is only my first week with C#, but I use actionscript a lot in Flash, so I have a very basic understanding of programming, but bear with me... I am trying to create a "FadeClass" that I can use to fade windows in my programs. I am using Visual C# 2008 Express right now. This is my "Form1.cs" in it's current state: using System;
0
8236
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
8679
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
8621
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
8475
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
7159
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...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
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
2606
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
1
1785
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.