473,505 Members | 15,212 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.Timer 'TIMER DECLARED HERE
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs)
t.Enabled = True
End Sub


---- DOES NOT BUILD ----

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

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim t As New System.Timers.Timer '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.EventArgs)
t.Enabled = True !!!!!!! CAUSES BUILD ERROR (t not declared)
End Sub


Nov 21 '05 #1
3 1950
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.Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
t = New System.Timers.Timer '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.EventArgs)
t.Enabled = True
End Sub

"Kris Palmer" <kr************@REMOVEyahoo.com> wrote in message
news:Xn**********************************@130.81.6 4.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.Timer 'TIMER DECLARED HERE
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs)
t.Enabled = True
End Sub


---- DOES NOT BUILD ----

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

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim t As New System.Timers.Timer '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.EventArgs)
t.Enabled = True !!!!!!! CAUSES BUILD ERROR (t not declared)
End Sub

Nov 21 '05 #2

"Kris Palmer" <kr************@REMOVEyahoo.com> 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
3367
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...
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
1705
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?...
5
7780
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....
5
8481
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...
8
3159
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 =...
5
12168
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...
0
1582
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...
4
2317
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...
0
7216
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
7098
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
7367
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
5613
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,...
1
5028
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...
0
4699
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
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 ...
1
754
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.