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

Creation of dynamic controls - Timers

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

Normally, to get the name of the control that has been fired you would do:

Private Sub Timeup(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)

Dim mytimer = DirectCast(sender, Control).Name.ToString

End Sub

The problem is that timers do not have a property called 'Name'. How can I
reference which timer is being fired?

Thanks

-Jerry
Nov 21 '05 #1
8 3151
Jerry,

Is there a special reason that you use the system.timers.timer. I like more
the simple use of the normal forms timer. Therefore I have made a sample
with that one.

It is based on just adding that Name that you want to the class. I have set
it on our website

http://www.windowsformsdatagridhelp....c-61641f5c8d9d

I hope this helps,

Cor
Nov 21 '05 #2
"Jerry Spence1" <je**********@somewhere.com> schrieb
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

Normally, to get the name of the control that has been fired you
would do:

Private Sub Timeup(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)

Dim mytimer = DirectCast(sender, Control).Name.ToString

End Sub

The problem is that timers do not have a property called 'Name'. How
can I reference which timer is being fired?

In addition to Cor,

an object can be identified by it's reference. If you don't store the
reference permanently, you can't identify it later. I don't know where you
create the Timer and where you need it. If it's in a Form, store it in a
Form's field instead of in a local variable:

'outside all subs (= a field in the form):
Dim NewTimer As System.Timers.Timer

Later use the 'Is' operator to see if it's a certain timer:

If sender is NewTimer Then
'...
elseif sender is AnotherTimerIfYouHaveOne then
'...
end if
Armin

Nov 21 '05 #3
Thanks Cor

I'm not sure what you mean by the 'normal' timer. There is a timer in the
components tab, and there is one in the forms tab - both seem to be
system.timers.timer. What's the difference?
-Jerry

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:O8**************@tk2msftngp13.phx.gbl...
Jerry,

Is there a special reason that you use the system.timers.timer. I like
more the simple use of the normal forms timer. Therefore I have made a
sample with that one.

It is based on just adding that Name that you want to the class. I have
set it on our website

http://www.windowsformsdatagridhelp....c-61641f5c8d9d

I hope this helps,

Cor

Nov 21 '05 #4
Thanks Armin

If it's reference is stored outside all Subs, then how can I create it
dynamically?

-Jerry

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uS*************@TK2MSFTNGP09.phx.gbl...
"Jerry Spence1" <je**********@somewhere.com> schrieb
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

Normally, to get the name of the control that has been fired you
would do:

Private Sub Timeup(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)

Dim mytimer = DirectCast(sender, Control).Name.ToString

End Sub

The problem is that timers do not have a property called 'Name'. How
can I reference which timer is being fired?

In addition to Cor,

an object can be identified by it's reference. If you don't store the
reference permanently, you can't identify it later. I don't know where you
create the Timer and where you need it. If it's in a Form, store it in a
Form's field instead of in a local variable:

'outside all subs (= a field in the form):
Dim NewTimer As System.Timers.Timer

Later use the 'Is' operator to see if it's a certain timer:

If sender is NewTimer Then
'...
elseif sender is AnotherTimerIfYouHaveOne then
'...
end if
Armin

Nov 21 '05 #5
Forget my last Cor - I've just looked a bit closer. Yes they are different.

Thanks for the example you did - you're the best!

-Jerry
"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
Thanks Cor

I'm not sure what you mean by the 'normal' timer. There is a timer in the
components tab, and there is one in the forms tab - both seem to be
system.timers.timer. What's the difference?
-Jerry

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:O8**************@tk2msftngp13.phx.gbl...
Jerry,

Is there a special reason that you use the system.timers.timer. I like
more the simple use of the normal forms timer. Therefore I have made a
sample with that one.

It is based on just adding that Name that you want to the class. I have
set it on our website

http://www.windowsformsdatagridhelp....c-61641f5c8d9d

I hope this helps,

Cor


Nov 21 '05 #6
"Jerry Spence1" <je**********@somewhere.com> schrieb
Thanks Armin

If it's reference is stored outside all Subs, then how can I create
it dynamically?


You can add them to an array list.

What I don't understand: If the number of Timers is not known at design
time, the reference is already the "key" to the timer. The 'sender' is
already pointing to the timer that fired the event. Why do you need another
way of identification? I would probably understand it if the number of
Timers was determined at design time. Then you could write code
distinguishing between Timers A, B and C, but as you want to add Timers
dynamically, this is obviously not the case. So, what's your intention?
Armin

Nov 21 '05 #7
Sorry - my knowledge of VB.Net isn't quite up to scratch to interpret what
you are saying about the 'key' to the timer.

The actual problem is that I have a number of IP based door swipes (access
control). When someone swipes a card, my program receives the card details
and processes it and opens the door (or not). It also creates a component
which receives and records an MPEG4 stream from a video source. That is all
working OK.

I also create a timer and set it to a value which is based on the length of
time that I want the video to be recorded of the person who swiped the card.
When the timer fires, it has to turn off the video stream from that
particular camera. The dynamic part is that I have no idea how many people
are likely to be swiping their cards at the same time, so I need to create
and destroy timers at will. On large installations this could be more than
20 (eg. in a college at home time). When the timer fires it will end up at a
common point, so I need to be able to identify it so that I know which video
stream to cut off.

- Jerry
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
"Jerry Spence1" <je**********@somewhere.com> schrieb
Thanks Armin

If it's reference is stored outside all Subs, then how can I create
it dynamically?


You can add them to an array list.

What I don't understand: If the number of Timers is not known at design
time, the reference is already the "key" to the timer. The 'sender' is
already pointing to the timer that fired the event. Why do you need
another
way of identification? I would probably understand it if the number of
Timers was determined at design time. Then you could write code
distinguishing between Timers A, B and C, but as you want to add Timers
dynamically, this is obviously not the case. So, what's your intention?
Armin

Nov 21 '05 #8
"Jerry Spence1" <je**********@somewhere.com> schrieb
Sorry - my knowledge of VB.Net isn't quite up to scratch to
interpret what you are saying about the 'key' to the timer.

The actual problem is that I have a number of IP based door swipes
(access control). When someone swipes a card, my program receives
the card details and processes it and opens the door (or not). It
also creates a component which receives and records an MPEG4 stream
from a video source. That is all working OK.

I also create a timer and set it to a value which is based on the
length of time that I want the video to be recorded of the person
who swiped the card. When the timer fires, it has to turn off the
video stream from that particular camera. The dynamic part is that I
have no idea how many people are likely to be swiping their cards at
the same time, so I need to create and destroy timers at will. On
large installations this could be more than 20 (eg. in a college at
home time). When the timer fires it will end up at a common point,
so I need to be able to identify it so that I know which video
stream to cut off.

I don't understand the video part, but... ;-)

.... I think you are looking for an _association_ between the timer and the
video stream. You can inherit from System.Windows.Forms.Timer and add a
property referencing the video stream or whatever object you created for
this purpose.

class VideoTimer
inherits System.Windows.Forms.Timer

public readonly additionaldata as ...

public sub new(byval additionaldata as ...)
me.additionaldata = additionaldata
end sub

end class

Instead of creating a System.Windows.Forms.Timer, create an instance of your
class, and add it to the arraylist I suggested before:

dim vt as videotimer
vt = new VideoTimer(VideoStream)
al.add(vt)
If you get the Timer's event, you can cast to VideoTimer and access the data
related to it:

dim vt as videotimer
vt = directcast(sender, videotimer)
vt.additionaldata.<whatever>

Armin

Nov 21 '05 #9

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

Similar topics

4
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...
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
3
by: Adie | last post by:
Hi, I wonder if anyone can tell me how to add user controls to a page dynamically? In context: I have a bunch of HTML tables which due to time constraints can't be populated to a database, so I...
3
by: PABruceFan | last post by:
I am dynamically adding rows to an asp:table as a result of a database query. The row consists of a label, a textbox and three checkboxes in that order: LABEL TEXTBOX CHECKBOX1 CHECKBOX3 ...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
3
by: Kris Palmer | last post by:
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...
2
by: jmgopi | last post by:
Hi: Can somebody provide me samples on how to create a dynamic CollapsiblePanel using ASP.NET AJAX Toolkit. Any points are highly appreciated. Thanks, GJM
1
by: lakshmipurna | last post by:
how can we create dynamic controls in asp.net with c# code i don't know about dynamic controls.
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.